docs: corrected json syntax in 7.esm.md (#24937)

This commit is contained in:
Soheil Nazari 2023-12-28 16:11:19 +01:00 committed by GitHub
parent f5676fba56
commit 155100edd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -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.
@ -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?
@ -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