Skip to content

Commit 1eb55f3

Browse files
joyeecheungtargos
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 c249289 commit 1eb55f3

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

doc/api/esm.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,12 +293,12 @@ mandatory:
293293
| ---------------- | ---------------- |
294294
| `'json'` | [JSON modules][] |
295295

296-
## Builtin modules
296+
## Built-in modules
297297

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

304304
```js
@@ -1145,8 +1145,8 @@ resolution for ESM specifiers is [commonjs-extension-resolution-loader][].
11451145
11461146
[6.1.7 Array Index]: https://tc39.es/ecma262/#integer-index
11471147
[Addons]: addons.md
1148+
[Built-in modules]: modules.md#built-in-modules
11481149
[CommonJS]: modules.md
1149-
[Core modules]: modules.md#core-modules
11501150
[Determining module system]: packages.md#determining-module-system
11511151
[Dynamic `import()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
11521152
[ES Module Integration Proposal for WebAssembly]: https://github.com/webassembly/esm-integration

doc/api/modules.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ them as different modules and will reload the file multiple times. For example,
380380
`require('./foo')` and `require('./FOO')` return two different objects,
381381
irrespective of whether or not `./foo` and `./FOO` are the same file.
382382

383-
## Core modules
383+
## Built-in modules
384384

385385
<!--type=misc-->
386386

@@ -396,20 +396,31 @@ changes:
396396
Node.js has several modules compiled into the binary. These modules are
397397
described in greater detail elsewhere in this documentation.
398398

399-
The core modules are defined within the Node.js source and are located in the
399+
The built-in modules are defined within the Node.js source and are located in the
400400
`lib/` folder.
401401

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

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

413+
### Built-in modules with mandatory `node:` prefix
414+
415+
When being loaded by `require()`, some built-in modules must be requested with the
416+
`node:` prefix. This requirement exists to prevent newly introduced built-in
417+
modules from having a conflict with user land packages that already have
418+
taken the name. Currently the built-in modules that requires the `node:` prefix are:
419+
420+
* [`node:sea`][]
421+
* [`node:test`][]
422+
* [`node:test/reporters`][]
423+
413424
## Cycles
414425

415426
<!--type=misc-->
@@ -552,7 +563,7 @@ folders as modules, and work for both `require` and `import`.
552563
<!--type=misc-->
553564

554565
If the module identifier passed to `require()` is not a
555-
[core](#core-modules) module, and does not begin with `'/'`, `'../'`, or
566+
[built-in](#built-in-modules) module, and does not begin with `'/'`, `'../'`, or
556567
`'./'`, then Node.js starts at the directory of the current module, and
557568
adds `/node_modules`, and attempts to load the module from that location.
558569
Node.js will not append `node_modules` to a path already ending in
@@ -1166,6 +1177,9 @@ This section was moved to
11661177
[`module.id`]: #moduleid
11671178
[`module` core module]: module.md
11681179
[`module` object]: #the-module-object
1180+
[`node:sea`]: single-executable-applications.md#single-executable-application-api
1181+
[`node:test/reporters`]: test.md#test-reporters
1182+
[`node:test`]: test.md
11691183
[`package.json`]: packages.md#nodejs-packagejson-field-definitions
11701184
[`path.dirname()`]: path.md#pathdirnamepath
11711185
[`require.main`]: #requiremain

0 commit comments

Comments
 (0)