Skip to content

Commit a8601ef

Browse files
joyeecheungmarco-ippolito
authored andcommitted
doc: improve explanation about built-in modules
PR-URL: #52762 Fixes: #52599 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Moshe Atlow <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Zijian Liu <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
1 parent 3a4a0eb commit a8601ef

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

doc/api/esm.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,12 @@ mandatory:
285285
| ---------------- | ---------------- |
286286
| `'json'` | [JSON modules][] |
287287

288-
## Builtin modules
288+
## Built-in modules
289289

290-
[Core modules][] provide named exports of their public API. A
290+
[Built-in modules][] provide named exports of their public API. A
291291
default export is also provided which is the value of the CommonJS exports.
292292
The default export can be used for, among other things, modifying the named
293-
exports. Named exports of builtin modules are updated only by calling
293+
exports. Named exports of built-in modules are updated only by calling
294294
[`module.syncBuiltinESMExports()`][].
295295

296296
```js
@@ -1128,8 +1128,8 @@ resolution for ESM specifiers is [commonjs-extension-resolution-loader][].
11281128
11291129
[6.1.7 Array Index]: https://tc39.es/ecma262/#integer-index
11301130
[Addons]: addons.md
1131+
[Built-in modules]: modules.md#built-in-modules
11311132
[CommonJS]: modules.md
1132-
[Core modules]: modules.md#core-modules
11331133
[Determining module system]: packages.md#determining-module-system
11341134
[Dynamic `import()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
11351135
[ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration

doc/api/modules.md

+20-6
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ them as different modules and will reload the file multiple times. For example,
312312
`require('./foo')` and `require('./FOO')` return two different objects,
313313
irrespective of whether or not `./foo` and `./FOO` are the same file.
314314

315-
## Core modules
315+
## Built-in modules
316316

317317
<!--type=misc-->
318318

@@ -328,20 +328,31 @@ changes:
328328
Node.js has several modules compiled into the binary. These modules are
329329
described in greater detail elsewhere in this documentation.
330330

331-
The core modules are defined within the Node.js source and are located in the
331+
The built-in modules are defined within the Node.js source and are located in the
332332
`lib/` folder.
333333

334-
Core modules can be identified using the `node:` prefix, in which case
334+
built-in modules can be identified using the `node:` prefix, in which case
335335
it bypasses the `require` cache. For instance, `require('node:http')` will
336336
always return the built in HTTP module, even if there is `require.cache` entry
337337
by that name.
338338

339-
Some core modules are always preferentially loaded if their identifier is
339+
Some built-in modules are always preferentially loaded if their identifier is
340340
passed to `require()`. For instance, `require('http')` will always
341341
return the built-in HTTP module, even if there is a file by that name. The list
342-
of core modules that can be loaded without using the `node:` prefix is exposed
342+
of built-in modules that can be loaded without using the `node:` prefix is exposed
343343
as [`module.builtinModules`][].
344344

345+
### Built-in modules with mandatory `node:` prefix
346+
347+
When being loaded by `require()`, some built-in modules must be requested with the
348+
`node:` prefix. This requirement exists to prevent newly introduced built-in
349+
modules from having a conflict with user land packages that already have
350+
taken the name. Currently the built-in modules that requires the `node:` prefix are:
351+
352+
* [`node:sea`][]
353+
* [`node:test`][]
354+
* [`node:test/reporters`][]
355+
345356
## Cycles
346357

347358
<!--type=misc-->
@@ -484,7 +495,7 @@ folders as modules, and work for both `require` and `import`.
484495
<!--type=misc-->
485496

486497
If the module identifier passed to `require()` is not a
487-
[core](#core-modules) module, and does not begin with `'/'`, `'../'`, or
498+
[built-in](#built-in-modules) module, and does not begin with `'/'`, `'../'`, or
488499
`'./'`, then Node.js starts at the directory of the current module, and
489500
adds `/node_modules`, and attempts to load the module from that location.
490501
Node.js will not append `node_modules` to a path already ending in
@@ -1097,6 +1108,9 @@ This section was moved to
10971108
[`module.id`]: #moduleid
10981109
[`module` core module]: module.md
10991110
[`module` object]: #the-module-object
1111+
[`node:sea`]: single-executable-applications.md#single-executable-application-api
1112+
[`node:test/reporters`]: test.md#test-reporters
1113+
[`node:test`]: test.md
11001114
[`package.json`]: packages.md#nodejs-packagejson-field-definitions
11011115
[`path.dirname()`]: path.md#pathdirnamepath
11021116
[`require.main`]: #requiremain

0 commit comments

Comments
 (0)