Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
64 changes: 39 additions & 25 deletions doc/api/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -1216,27 +1216,6 @@

Enable experimental support for the QUIC protocol.

### `--experimental-require-module`

<!-- YAML
added:
- v22.0.0
- v20.17.0
changes:
- version:
- v23.0.0
- v22.12.0
- v20.19.0
pr-url: https://github.com/nodejs/node/pull/55085
description: This is now true by default.
-->

> Stability: 1.1 - Active Development

Supports loading a synchronous ES module graph in `require()`.

See [Loading ECMAScript modules using `require()`][].

### `--experimental-sea-config`

<!-- YAML
Expand Down Expand Up @@ -1908,6 +1887,11 @@
- v22.0.0
- v20.17.0
changes:
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/60959
description: The flag was renamed from `--no-experimental-require-module` to
`--no-require-module`, with the former marked as legacy.
- version:
- v23.0.0
- v22.12.0
Expand All @@ -1916,11 +1900,9 @@
description: This is now false by default.
-->

> Stability: 1.1 - Active Development

Disable support for loading a synchronous ES module graph in `require()`.
> Stability: 3 - Legacy: Use [`--no-require-module`][] instead.

See [Loading ECMAScript modules using `require()`][].
Legacy alias for [`--no-require-module`][].

### `--no-experimental-sqlite`

Expand Down Expand Up @@ -1999,6 +1981,36 @@
Disables the family autoselection algorithm unless connection options explicitly
enables it.

<a id="--experimental-require-module"></a>

### `--no-require-module`

<!-- YAML
added:
- v22.0.0
- v20.17.0
changes:
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/60959
description: This flag is no longer experimental.
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/60959
description: This flag was renamed from `--no-experimental-require-module`
to `--no-require-module`.
- version:
- v23.0.0
- v22.12.0
- v20.19.0
pr-url: https://github.com/nodejs/node/pull/55085

Check warning on line 2006 in doc/api/cli.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: This is now false by default.
-->

Disable support for loading a synchronous ES module graph in `require()`.

See [Loading ECMAScript modules using `require()`][].

### `--no-strip-types`

<!-- YAML
Expand Down Expand Up @@ -3612,6 +3624,7 @@
* `--report-on-signal`
* `--report-signal`
* `--report-uncaught-exception`
* `--require-module`
* `--require`, `-r`
* `--secure-heap-min`
* `--secure-heap`
Expand Down Expand Up @@ -4154,6 +4167,7 @@
[`--experimental-sea-config`]: single-executable-applications.md#generating-single-executable-preparation-blobs
[`--heap-prof-dir`]: #--heap-prof-dir
[`--import`]: #--importmodule
[`--no-require-module`]: #--no-require-module
[`--no-strip-types`]: #--no-strip-types
[`--openssl-config`]: #--openssl-configfile
[`--preserve-symlinks`]: #--preserve-symlinks
Expand Down
4 changes: 0 additions & 4 deletions doc/api/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -2661,8 +2661,6 @@ A QUIC session failed because version negotiation is required.

### `ERR_REQUIRE_ASYNC_MODULE`

> Stability: 1 - Experimental

When trying to `require()` a [ES Module][], the module turns out to be asynchronous.
That is, it contains top-level await.

Expand All @@ -2674,8 +2672,6 @@ before looking for the top-level awaits).

### `ERR_REQUIRE_CYCLE_MODULE`

> Stability: 1 - Experimental

When trying to `require()` a [ES Module][], a CommonJS to ESM or ESM to CommonJS edge
participates in an immediate cycle.
This is not allowed because ES Modules cannot be evaluated while they are
Expand Down
14 changes: 8 additions & 6 deletions doc/api/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ added:
- v22.0.0
- v20.17.0
changes:
- version:
- REPLACEME
pr-url: https://github.com/nodejs/node/pull/60959
description: This feature is no longer experimental.
- version:
- v23.5.0
- v22.13.0
Expand All @@ -195,8 +199,6 @@ changes:
description: Support `'module.exports'` interop export in `require(esm)`.
-->

> Stability: 1.2 - Release candidate

The `.mjs` extension is reserved for [ECMAScript Modules][].
See [Determining module system][] section for more info
regarding which files are parsed as ECMAScript modules.
Expand Down Expand Up @@ -324,8 +326,8 @@ If `--experimental-print-required-tla` is enabled, instead of throwing
module, try to locate the top-level awaits, and print their location to
help users fix them.

Support for loading ES modules using `require()` is currently
experimental and can be disabled using `--no-experimental-require-module`.
If support for loading ES modules using `require()` results in unexpected
breakage, it can be disabled using `--no-require-module`.
To print where this feature is used, use [`--trace-require-module`][].

This feature can be detected by checking if
Expand Down Expand Up @@ -422,7 +424,7 @@ LOAD_PACKAGE_IMPORTS(X, DIR)
1. Find the closest package scope SCOPE to DIR.
2. If no scope was found, return.
3. If the SCOPE/package.json "imports" is null or undefined, return.
4. If `--experimental-require-module` is enabled
4. If `--no-require-module` is not enabled
a. let CONDITIONS = ["node", "require", "module-sync"]
b. Else, let CONDITIONS = ["node", "require"]
5. let MATCH = PACKAGE_IMPORTS_RESOLVE(X, pathToFileURL(SCOPE),
Expand All @@ -436,7 +438,7 @@ LOAD_PACKAGE_EXPORTS(X, DIR)
return.
3. Parse DIR/NAME/package.json, and look for "exports" field.
4. If "exports" is null or undefined, return.
5. If `--experimental-require-module` is enabled
5. If `--no-require-module` is not enabled
a. let CONDITIONS = ["node", "require", "module-sync"]
b. Else, let CONDITIONS = ["node", "require"]
6. let MATCH = PACKAGE_EXPORTS_RESOLVE(pathToFileURL(DIR/NAME), "." + SUBPATH,
Expand Down
3 changes: 3 additions & 0 deletions doc/node.1
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ Disable top-level await keyword support in REPL.
.It Fl -no-experimental-sqlite
Disable the experimental node:sqlite module.
.
.It Fl -no-require-module
Disable support for loading ECMAScript modules with require().
.
.It Fl -no-strip-types
Disable type-stripping for TypeScript files.
.
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ const features = {
return binding.hasCachedBuiltins();
},
get require_module() {
return getOptionValue('--experimental-require-module');
return getOptionValue('--require-module');
},
get quic() {
// TODO(@jasnell): When the implementation is updated to support Boring,
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,7 @@ function wrapSafe(filename, content, cjsModuleInstance, format) {
} else {
// For modules being loaded by `require()`, if require(esm) is disabled,
// don't try to reparse to detect format and just throw for ESM syntax.
shouldDetectModule = getOptionValue('--experimental-require-module');
shouldDetectModule = getOptionValue('--require-module');
}
}
const result = compileFunctionForCJSLoader(content, filename, false /* is_sea_main */, shouldDetectModule);
Expand Down Expand Up @@ -1884,7 +1884,7 @@ Module._extensions['.js'] = function(module, filename) {
const { source, format: loadedFormat } = loadSource(module, filename, format);
// Function require shouldn't be used in ES modules when require(esm) is disabled.
if ((loadedFormat === 'module' || loadedFormat === 'module-typescript') &&
!getOptionValue('--experimental-require-module')) {
!getOptionValue('--require-module')) {
const err = getRequireESMError(module, pkg, source, filename);
throw err;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class ModuleLoader {
*/
importSyncForRequire(mod, filename, source, isMain, parent) {
const url = pathToFileURL(filename).href;
if (!getOptionValue('--experimental-require-module')) {
if (!getOptionValue('--require-module')) {
throw new ERR_REQUIRE_ESM(url, true);
}

Expand Down Expand Up @@ -489,7 +489,7 @@ class ModuleLoader {
}

if (formatFromLoad === 'module' || formatFromLoad === 'module-typescript') {
if (!getOptionValue('--experimental-require-module')) {
if (!getOptionValue('--require-module')) {
throw new ERR_REQUIRE_ESM(url, true);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/esm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function initializeDefaultConditions() {
const userConditions = getOptionValue('--conditions');
const noAddons = getOptionValue('--no-addons');
const addonConditions = noAddons ? [] : ['node-addons'];
const moduleConditions = getOptionValue('--experimental-require-module') ? ['module-sync'] : [];
const moduleConditions = getOptionValue('--require-module') ? ['module-sync'] : [];
defaultConditions = ObjectFreeze([
'node',
'import',
Expand Down
2 changes: 1 addition & 1 deletion lib/internal/modules/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ function initializeCjsConditions() {
...addonConditions,
...userConditions,
];
if (getOptionValue('--experimental-require-module')) {
if (getOptionValue('--require-module')) {
cjsConditionsArray.push('module-sync');
}
ObjectFreeze(cjsConditionsArray);
Expand Down
10 changes: 8 additions & 2 deletions src/node_options.cc
Original file line number Diff line number Diff line change
Expand Up @@ -487,17 +487,23 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
kAllowedInEnvvar,
true);
AddOption("--experimental-print-required-tla",
"Print pending top-level await. If --experimental-require-module "
"Print pending top-level await. If --require-module "
"is true, evaluate asynchronous graphs loaded by `require()` but "
"do not run the microtasks, in order to to find and print "
"top-level await in the graph",
&EnvironmentOptions::print_required_tla,
kAllowedInEnvvar);
AddOption("--experimental-require-module",
AddOption("--require-module",
"Allow loading synchronous ES Modules in require().",
&EnvironmentOptions::require_module,
kAllowedInEnvvar,
true);
AddOption("--experimental-require-module",
"Legacy alias for --require-module",
&EnvironmentOptions::require_module,
kAllowedInEnvvar,
true);
Implies("--experimental-require-module", "--require-module");
AddOption("--diagnostic-dir",
"set dir for all output files"
" (default: current working directory)",
Expand Down
Loading