|
6 | 6 |
|
7 | 7 | <!--name=esm--> |
8 | 8 |
|
9 | | -Node contains support for ES Modules based upon the [the Node EP for ES Modules][]. |
| 9 | +Node.js contains support for ES Modules based upon the |
| 10 | +[Node.js EP for ES Modules][]. |
10 | 11 |
|
11 | | -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. |
| 12 | +Not all features of the EP are complete and will be landing as both VM support |
| 13 | +and implementation is ready. Error messages are still being polished. |
12 | 14 |
|
13 | 15 | ## Enabling |
14 | 16 |
|
15 | 17 | <!-- type=misc --> |
16 | 18 |
|
17 | | -The `--experimental-modules` flag can be used to enable features for loading ESM modules. |
| 19 | +The `--experimental-modules` flag can be used to enable features for loading |
| 20 | +ESM modules. |
18 | 21 |
|
19 | | -Once this has been set, files ending with `.mjs` will be able to be loaded as ES Modules. |
| 22 | +Once this has been set, files ending with `.mjs` will be able to be loaded |
| 23 | +as ES Modules. |
20 | 24 |
|
21 | 25 | ```sh |
22 | 26 | node --experimental-modules my-app.mjs |
@@ -28,7 +32,9 @@ node --experimental-modules my-app.mjs |
28 | 32 |
|
29 | 33 | ### Supported |
30 | 34 |
|
31 | | -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. |
| 35 | +Only the CLI argument for the main entry point to the program can be an entry |
| 36 | +point into an ESM graph. In the future `import()` can be used to create entry |
| 37 | +points into ESM graphs at run time. |
32 | 38 |
|
33 | 39 | ### Unsupported |
34 | 40 |
|
@@ -43,21 +49,26 @@ Only the CLI argument for the main entry point to the program can be an entry po |
43 | 49 |
|
44 | 50 | ### No NODE_PATH |
45 | 51 |
|
46 | | -`NODE_PATH` is not part of resolving `import` specifiers. Please use symlinks if this behavior is desired. |
| 52 | +`NODE_PATH` is not part of resolving `import` specifiers. Please use symlinks |
| 53 | +if this behavior is desired. |
47 | 54 |
|
48 | 55 | ### No `require.extensions` |
49 | 56 |
|
50 | | -`require.extensions` is not used by `import`. The expectation is that loader hooks can provide this workflow in the future. |
| 57 | +`require.extensions` is not used by `import`. The expectation is that loader |
| 58 | +hooks can provide this workflow in the future. |
51 | 59 |
|
52 | 60 | ### No `require.cache` |
53 | 61 |
|
54 | 62 | `require.cache` is not used by `import`. It has a separate cache. |
55 | 63 |
|
56 | 64 | ### URL based paths |
57 | 65 |
|
58 | | -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. |
| 66 | +ESM are resolved and cached based upon [URL](https://url.spec.whatwg.org/) |
| 67 | +semantics. This means that files containing special characters such as `#` and |
| 68 | +`?` need to be escaped. |
59 | 69 |
|
60 | | -Modules will be loaded multiple times if the `import` specifier used to resolve them have a different query or fragment. |
| 70 | +Modules will be loaded multiple times if the `import` specifier used to resolve |
| 71 | +them have a different query or fragment. |
61 | 72 |
|
62 | 73 | ```js |
63 | 74 | 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. |
70 | 81 |
|
71 | 82 | All CommonJS, JSON, and C++ modules can be used with `import`. |
72 | 83 |
|
73 | | -Modules loaded this way will only be loaded once, even if their query or fragment string differs between `import` statements. |
| 84 | +Modules loaded this way will only be loaded once, even if their query |
| 85 | +or fragment string differs between `import` statements. |
74 | 86 |
|
75 | | -When loaded via `import` these modules will provide a single `default` export representing the value of `module.exports` at the time they finished evaluating. |
| 87 | +When loaded via `import` these modules will provide a single `default` export |
| 88 | +representing the value of `module.exports` at the time they finished evaluating. |
76 | 89 |
|
77 | 90 | ```js |
78 | 91 | import fs from 'fs'; |
@@ -85,4 +98,4 @@ fs.readFile('./foo.txt', (err, body) => { |
85 | 98 | }); |
86 | 99 | ``` |
87 | 100 |
|
88 | | -[the Node EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md |
| 101 | +[Node.js EP for ES Modules]: https://github.com/nodejs/node-eps/blob/master/002-es-modules.md |