Skip to content

Commit ce3edd0

Browse files
committed
fixup!
1 parent c19d161 commit ce3edd0

File tree

3 files changed

+41
-3
lines changed

3 files changed

+41
-3
lines changed

doc/api/cli.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ under any of the following conditions:
3838
point to be loaded with ECMAScript module loader.
3939

4040
Otherwise, the file is loaded using the CommonJS module loader. See
41-
[File modules][] for more details.
41+
[Modules loaders][] for more details.
4242

4343
### ECMAScript modules loader entry point caveat
4444

@@ -1956,7 +1956,7 @@ $ node --max-old-space-size=1536 index.js
19561956
[Chrome DevTools Protocol]: https://chromedevtools.github.io/devtools-protocol/
19571957
[CommonJS]: modules.md
19581958
[ECMAScript module loader]: esm.md#loaders
1959-
[File modules]: modules.md#file-modules
1959+
[Modules loaders]: packages.md#modules-loaders
19601960
[OSSL_PROVIDER-legacy]: https://www.openssl.org/docs/man3.0/man7/OSSL_PROVIDER-legacy.html
19611961
[REPL]: repl.md
19621962
[ScriptCoverage]: https://chromedevtools.github.io/devtools-protocol/tot/Profiler#type-ScriptCoverage

doc/api/packages.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,41 @@ future-proof the package in case the default type of Node.js ever changes, and
8585
it will also make things easier for build tools and loaders to determine how the
8686
files in the package should be interpreted.
8787

88+
### Modules loaders
89+
90+
Node.js has two system for resolving a specifier and load modules.
91+
92+
There is the CommonJS module loader:
93+
94+
* It is fully synchronous.
95+
* It is monkey patchable.
96+
* When resolving a specifier, if no exact match is found, it will try to add
97+
extensions (`.js`, `.json`, and finally `.node`).
98+
* It supports [folders as modules][].
99+
* It treats `.json` as JSON text files.
100+
* `.node` files are interpreted as compiled addon modules loaded with
101+
`process.dlopen()`.
102+
* It treats files that do not have `.json` or `.node` extension as JavaScript
103+
text files.
104+
* It cannot be used to load ECMAScript modules. Attempting to do so will result
105+
in a [`ERR_REQUIRE_ESM`][] error.
106+
* It can be accessed using `require` function.
107+
108+
There is the ECMAScript module loader:
109+
110+
* It is Asynchronous.
111+
* It is not monkey patchable, can be customized using [loader hooks][].
112+
* No extension searching, the specifier must point to the exact URL of the file.
113+
* It does not support folders as modules.
114+
* Import assertion are needed to load JSON modules (behind
115+
`--experimental-json-modules` flag).
116+
* It only accepts `.js`, `.mjs`, and `.cjs` extensions for JavaScript text
117+
files.
118+
* It can be used to load (JavaScript) CommonJS modules. It passes the module
119+
content through the `es-module-lexer` to assess what are its exports, convert
120+
its URL to an absolute path and load it using the CommonJS module loader.
121+
* It can be accessed using `import`.
122+
88123
### `package.json` and file extensions
89124

90125
Within a package, the [`package.json`][] [`"type"`][] field defines how
@@ -1235,9 +1270,12 @@ This field defines [subpath imports][] for the current package.
12351270
[`--conditions` / `-C` flag]: #resolving-user-conditions
12361271
[`--no-addons` flag]: cli.md#--no-addons
12371272
[`ERR_PACKAGE_PATH_NOT_EXPORTED`]: errors.md#err_package_path_not_exported
1273+
[`ERR_REQUIRE_ESM`]: errors.md#err_require_esm
12381274
[`esm`]: https://github.com/standard-things/esm#readme
12391275
[`package.json`]: #nodejs-packagejson-field-definitions
12401276
[entry points]: #package-entry-points
1277+
[folders as modules]: modules.md#folders-as-modules
1278+
[loader hooks]: esm.md#loaders
12411279
[self-reference]: #self-referencing-a-package-using-its-name
12421280
[subpath exports]: #subpath-exports
12431281
[subpath imports]: #subpath-imports

tools/doc/links-mapper.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
"command line options": "cli.html#options",
44
"web server": "http.html"
55
}
6-
}
6+
}

0 commit comments

Comments
 (0)