Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! doc: correct module loading descriptions
Co-authored-by: Jacob Smith <3012099+JakobJingleheimer@users.noreply.github.com>
  • Loading branch information
joyeecheung and JakobJingleheimer authored Oct 31, 2025
commit b10e129c4a3022c85d111756e58a7d634847f25c
4 changes: 2 additions & 2 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ directory. That entry point string is then resolved as if it's been requested
by `require()` from the current working directory. If no corresponding file
is found, an error is thrown.

The resolved path is usually also loaded as if it's been requested by `require()`,
unless one of the conditions below apply, then it's loaded as if it's been requested
By default, the resolved path is also loaded as if it's been requested by `require()`,
unless one of the conditions below applythen it's loaded as if it's been requested
by `import()`:

* The program was started with a command-line flag that forces the entry
Expand Down
7 changes: 4 additions & 3 deletions doc/api/packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ When a module is requested via `require()`:
* Files with any other extension, or without extensions, are treated as JavaScript
text files.
* `require()` can only be used to [load ECMAScript modules from CommonJS modules][] if
the [ECMAScript module][ES Module] and its dependencies are synchronous
the [ECMAScript module][ES Module] _and its dependencies_ are synchronous
(i.e. they do not contain top-level `await`).

When a module is requested via `import` statements or `import()` expressions:
Expand All @@ -183,12 +183,13 @@ When a module is requested via `import` statements or `import()` expressions:
files.
* `.wasm` files are treated as [WebAssembly modules][].
* Any other file extensions will result in a [`ERR_UNKNOWN_FILE_EXTENSION`][] error.
Comment thread
joyeecheung marked this conversation as resolved.
Additional file extensions can be facilitated via [customization hooks][].
* `import`/`import()` can be used to load JavaScript [CommonJS modules][commonjs].
Such modules are passed through the `cjs-module-lexer` to try to identify named
exports, which are available if they can be determined through static analysis.

Regardless of how a module is requested, the resolution and loading process can be customized
using [loader hooks][].
using [customization hooks][].

### `package.json` and file extensions

Expand Down Expand Up @@ -1176,7 +1177,7 @@ This field defines [subpath imports][] for the current package.
[folders as modules]: modules.md#folders-as-modules
[import maps]: https://github.com/WICG/import-maps
[load ECMAScript modules from CommonJS modules]: modules.md#loading-ecmascript-modules-using-require
[loader hooks]: module.md#customization-hooks
[customization hooks]: module.md#customization-hooks
[packages folder mapping]: https://github.com/WICG/import-maps#packages-via-trailing-slashes
[self-reference]: #self-referencing-a-package-using-its-name
[subpath exports]: #subpath-exports
Expand Down
Loading