diff --git a/doc/api/esm.md b/doc/api/esm.md index 862fcae43aa5f2..b36965e41181ed 100644 --- a/doc/api/esm.md +++ b/doc/api/esm.md @@ -60,7 +60,7 @@ or when referenced by `import` statements within ES module code: * Strings passed in as an argument to `--eval` or `--print`, or piped to `node` via `STDIN`, with the flag `--input-type=commonjs`. -### package.json "type" field +### `package.json` `"type"` field Files ending with `.js` or `.mjs`, or lacking any extension, will be loaded as ES modules when the nearest parent `package.json` file @@ -162,7 +162,7 @@ package scope: extension (since both `.js` and `.cjs` files are treated as CommonJS within a `"commonjs"` package scope). -### --input-type flag +### `--input-type` flag Strings passed in as an argument to `--eval` or `--print` (or `-e` or `-p`), or piped to `node` via `STDIN`, will be treated as ES modules when the @@ -358,7 +358,7 @@ in order to be forward-compatible with fallback workflows in future: Since `"not:valid"` is not a supported target, `"./submodule.js"` is used instead as the fallback, as if it were the only target. -## import Specifiers +## `import` Specifiers ### Terminology @@ -415,7 +415,7 @@ import 'data:text/javascript,console.log("hello!");'; import _ from 'data:application/json,"world!"'; ``` -## import.meta +## `import.meta` * {Object} @@ -434,12 +434,12 @@ indexes (e.g. `'./startup/index.js'`) must also be fully specified. This behavior matches how `import` behaves in browser environments, assuming a typically configured server. -### No NODE_PATH +### No `NODE_PATH` `NODE_PATH` is not part of resolving `import` specifiers. Please use symlinks if this behavior is desired. -### No require, exports, module.exports, \_\_filename, \_\_dirname +### No `require`, `exports`, `module.exports`, `__filename`, `__dirname` These CommonJS variables are not available in ES modules. @@ -456,12 +456,12 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); ``` -### 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. -### No require.cache +### No `require.cache` `require.cache` is not used by `import`. It has a separate cache. @@ -483,7 +483,7 @@ For now, only modules using the `file:` protocol can be loaded. ## Interoperability with CommonJS -### require +### `require` `require` always treats the files it references as CommonJS. This applies whether `require` is used the traditional way within a CommonJS environment, or @@ -491,7 +491,7 @@ in an ES module environment using [`module.createRequire()`][]. To include an ES module into CommonJS, use [`import()`][]. -### import statements +### `import` statements An `import` statement can reference an ES module, a CommonJS module, or JSON. Other file types such as Native modules are not supported. For those, @@ -523,7 +523,7 @@ import { sin, cos } from 'geometry/trigonometry-functions.mjs'; > > There are ongoing efforts to make the latter code possible. -### import() expressions +### `import()` expressions Dynamic `import()` is supported in both CommonJS and ES modules. It can be used to include ES module files from CommonJS code.