Skip to content

Commit

Permalink
corrected json syntax in 7.esm.md
Browse files Browse the repository at this point in the history
It should be `"type": "module"` and not `type: 'module'`
  • Loading branch information
s0h311 committed Dec 28, 2023
1 parent f5676fb commit ba3adc9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions docs/2.guide/1.concepts/7.esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ So in Nuxt 2, the bundler (webpack) would pull in the CJS file ('main') for the

However, in recent Node.js LTS releases, it is now possible to [use native ESM module](https://nodejs.org/api/esm.html) within Node.js. That means that Node.js itself can process JavaScript using ESM syntax, although it doesn't do it by default. The two most common ways to enable ESM syntax are:

- set `type: 'module'` within your `package.json` and keep using `.js` extension
- set `"type": "module"` within your `package.json` and keep using `.js` extension
- use the `.mjs` file extensions (recommended)

This is what we do for Nuxt Nitro; we output a `.output/server/index.mjs` file. That tells Node.js to treat this file as a native ES module.
Expand All @@ -67,7 +67,7 @@ Node supports the following kinds of imports (see [docs](https://nodejs.org/api/

1. files ending in `.mjs` - these are expected to use ESM syntax
1. files ending in `.cjs` - these are expected to use CJS syntax
1. files ending in `.js` - these are expected to use CJS syntax unless their `package.json` has `type: 'module'`
1. files ending in `.js` - these are expected to use CJS syntax unless their `package.json` has `"type": "module"`

### What Kinds of Problems Can There Be?

Expand Down Expand Up @@ -211,7 +211,7 @@ The good news is that it's relatively simple to fix issues of ESM compatibility.
1. **You can opt to make your entire library ESM-only**.
This would mean setting `type: 'module'` in your `package.json` and ensuring that your built library uses ESM syntax. However, you may face issues with your dependencies - and this approach means your library can _only_ be consumed in an ESM context.
This would mean setting `"type": "module"` in your `package.json` and ensuring that your built library uses ESM syntax. However, you may face issues with your dependencies - and this approach means your library can _only_ be consumed in an ESM context.
### Migration
Expand Down

0 comments on commit ba3adc9

Please sign in to comment.