doc: fix nits in esm.md
* Fix some abbreviated wording, a typo and a link. * Wrap long lines at 80 characters. PR-URL: https://github.com/nodejs/node/pull/15315 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
parent
cb94905774
commit
b4b7ac6ae8
@ -6,17 +6,21 @@
|
|||||||
|
|
||||||
<!--name=esm-->
|
<!--name=esm-->
|
||||||
|
|
||||||
Node contains support for ES Modules based upon the [the Node EP for ES Modules][].
|
Node.js contains support for ES Modules based upon the
|
||||||
|
[Node.js EP for ES Modules][].
|
||||||
|
|
||||||
Not all features of the EP are complete and will be landing as both VM support and implementation is ready. Error messages are still being polished.
|
Not all features of the EP are complete and will be landing as both VM support
|
||||||
|
and implementation is ready. Error messages are still being polished.
|
||||||
|
|
||||||
## Enabling
|
## Enabling
|
||||||
|
|
||||||
<!-- type=misc -->
|
<!-- type=misc -->
|
||||||
|
|
||||||
The `--experimental-modules` flag can be used to enable features for loading ESM modules.
|
The `--experimental-modules` flag can be used to enable features for loading
|
||||||
|
ESM modules.
|
||||||
|
|
||||||
Once this has been set, files ending with `.mjs` will be able to be loaded as ES Modules.
|
Once this has been set, files ending with `.mjs` will be able to be loaded
|
||||||
|
as ES Modules.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
node --experimental-modules my-app.mjs
|
node --experimental-modules my-app.mjs
|
||||||
@ -28,7 +32,9 @@ node --experimental-modules my-app.mjs
|
|||||||
|
|
||||||
### Supported
|
### Supported
|
||||||
|
|
||||||
Only the CLI argument for the main entry point to the program can be an entry point into an ESM graph. In the future `import()` can be used to create entry points into ESM graphs at run time.
|
Only the CLI argument for the main entry point to the program can be an entry
|
||||||
|
point into an ESM graph. In the future `import()` can be used to create entry
|
||||||
|
points into ESM graphs at run time.
|
||||||
|
|
||||||
### Unsupported
|
### Unsupported
|
||||||
|
|
||||||
@ -43,11 +49,13 @@ Only the CLI argument for the main entry point to the program can be an entry po
|
|||||||
|
|
||||||
### No NODE_PATH
|
### No NODE_PATH
|
||||||
|
|
||||||
`NODE_PATH` is not part of resolving `import` specifiers. Please use symlinks if this behavior is desired.
|
`NODE_PATH` is not part of resolving `import` specifiers. Please use symlinks
|
||||||
|
if this behavior is desired.
|
||||||
|
|
||||||
### No `require.extensions`
|
### No `require.extensions`
|
||||||
|
|
||||||
`require.extensions` is not used by `import`. The expectation is that loader hooks can provide this workflow in the future.
|
`require.extensions` is not used by `import`. The expectation is that loader
|
||||||
|
hooks can provide this workflow in the future.
|
||||||
|
|
||||||
### No `require.cache`
|
### No `require.cache`
|
||||||
|
|
||||||
@ -55,9 +63,12 @@ Only the CLI argument for the main entry point to the program can be an entry po
|
|||||||
|
|
||||||
### URL based paths
|
### URL based paths
|
||||||
|
|
||||||
ESM are resolved and cached based upon [URL](url.spec.whatwg.org) semantics. This means that files containing special characters such as `#` and `?` need to be escaped.
|
ESM are resolved and cached based upon [URL](https://url.spec.whatwg.org/)
|
||||||
|
semantics. This means that files containing special characters such as `#` and
|
||||||
|
`?` need to be escaped.
|
||||||
|
|
||||||
Modules will be loaded multiple times if the `import` specifier used to resolve them have a different query or fragment.
|
Modules will be loaded multiple times if the `import` specifier used to resolve
|
||||||
|
them have a different query or fragment.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import './foo?query=1'; // loads ./foo with query of "?query=1"
|
import './foo?query=1'; // loads ./foo with query of "?query=1"
|
||||||
@ -70,9 +81,11 @@ For now, only modules using the `file:` protocol can be loaded.
|
|||||||
|
|
||||||
All CommonJS, JSON, and C++ modules can be used with `import`.
|
All CommonJS, JSON, and C++ modules can be used with `import`.
|
||||||
|
|
||||||
Modules loaded this way will only be loaded once, even if their query or fragment string differs between `import` statements.
|
Modules loaded this way will only be loaded once, even if their query
|
||||||
|
or fragment string differs between `import` statements.
|
||||||
|
|
||||||
When loaded via `import` these modules will provide a single `default` export representing the value of `module.exports` at the time they finished evaluating.
|
When loaded via `import` these modules will provide a single `default` export
|
||||||
|
representing the value of `module.exports` at the time they finished evaluating.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
@ -85,4 +98,4 @@ fs.readFile('./foo.txt', (err, body) => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
[the Node EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
|
[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md
|
||||||
|
Loading…
x
Reference in New Issue
Block a user