Skip to content

Commit 77da57e

Browse files
committed
cli: add --require-module/--no-require-module
To replace --experimental-require-module and --no-experimental-require-module. The experimental ones are left as legacy aliases.
1 parent 85852a3 commit 77da57e

File tree

9 files changed

+59
-38
lines changed

9 files changed

+59
-38
lines changed

doc/api/cli.md

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,27 +1216,6 @@ added: v25.0.0
12161216
12171217
Enable experimental support for the QUIC protocol.
12181218

1219-
### `--experimental-require-module`
1220-
1221-
<!-- YAML
1222-
added:
1223-
- v22.0.0
1224-
- v20.17.0
1225-
changes:
1226-
- version:
1227-
- v23.0.0
1228-
- v22.12.0
1229-
- v20.19.0
1230-
pr-url: https://github.com/nodejs/node/pull/55085
1231-
description: This is now true by default.
1232-
-->
1233-
1234-
> Stability: 1.1 - Active Development
1235-
1236-
Supports loading a synchronous ES module graph in `require()`.
1237-
1238-
See [Loading ECMAScript modules using `require()`][].
1239-
12401219
### `--experimental-sea-config`
12411220

12421221
<!-- YAML
@@ -1908,6 +1887,11 @@ added:
19081887
- v22.0.0
19091888
- v20.17.0
19101889
changes:
1890+
- version:
1891+
- REPLACEME
1892+
pr-url: https://github.com/nodejs/node/pull/60959
1893+
description: The flag was renamed from `--no-experimental-require-module` to
1894+
`--no-require-module`, with the former marked as legacy.
19111895
- version:
19121896
- v23.0.0
19131897
- v22.12.0
@@ -1916,11 +1900,9 @@ changes:
19161900
description: This is now false by default.
19171901
-->
19181902

1919-
> Stability: 1.1 - Active Development
1920-
1921-
Disable support for loading a synchronous ES module graph in `require()`.
1903+
> Stability: 3 - Legacy: Use [`--no-require-module`][] instead.
19221904
1923-
See [Loading ECMAScript modules using `require()`][].
1905+
Legacy alias for [`--no-require-module`][].
19241906

19251907
### `--no-experimental-sqlite`
19261908

@@ -1999,6 +1981,34 @@ changes:
19991981
Disables the family autoselection algorithm unless connection options explicitly
20001982
enables it.
20011983

1984+
<a id="--experimental-require-module"></a>
1985+
1986+
### `--no-require-module`
1987+
1988+
<!-- YAML
1989+
added:
1990+
- v22.0.0
1991+
- v20.17.0
1992+
changes:
1993+
- version:
1994+
- REPLACEME
1995+
pr-url: https://github.com/nodejs/node/pull/60959
1996+
description: This flag was renamed from `--no-experimental-require-module`
1997+
to `--no-require-module`.
1998+
- version:
1999+
- v23.0.0
2000+
- v22.12.0
2001+
- v20.19.0
2002+
pr-url: https://github.com/nodejs/node/pull/55085
2003+
description: This is now false by default.
2004+
-->
2005+
2006+
> Stability: 1.2 - Release Candidate
2007+
2008+
Disable support for loading a synchronous ES module graph in `require()`.
2009+
2010+
See [Loading ECMAScript modules using `require()`][].
2011+
20022012
### `--no-strip-types`
20032013

20042014
<!-- YAML
@@ -3612,6 +3622,7 @@ one is included in the list below.
36123622
* `--report-on-signal`
36133623
* `--report-signal`
36143624
* `--report-uncaught-exception`
3625+
* `--require-module`
36153626
* `--require`, `-r`
36163627
* `--secure-heap-min`
36173628
* `--secure-heap`
@@ -4154,6 +4165,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
41544165
[`--experimental-sea-config`]: single-executable-applications.md#generating-single-executable-preparation-blobs
41554166
[`--heap-prof-dir`]: #--heap-prof-dir
41564167
[`--import`]: #--importmodule
4168+
[`--no-require-module`]: #--no-require-module
41574169
[`--no-strip-types`]: #--no-strip-types
41584170
[`--openssl-config`]: #--openssl-configfile
41594171
[`--preserve-symlinks`]: #--preserve-symlinks

doc/api/modules.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ If `--experimental-print-required-tla` is enabled, instead of throwing
324324
module, try to locate the top-level awaits, and print their location to
325325
help users fix them.
326326

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

331331
This feature can be detected by checking if
@@ -422,7 +422,7 @@ LOAD_PACKAGE_IMPORTS(X, DIR)
422422
1. Find the closest package scope SCOPE to DIR.
423423
2. If no scope was found, return.
424424
3. If the SCOPE/package.json "imports" is null or undefined, return.
425-
4. If `--experimental-require-module` is enabled
425+
4. If `--no-require-module` is not enabled
426426
a. let CONDITIONS = ["node", "require", "module-sync"]
427427
b. Else, let CONDITIONS = ["node", "require"]
428428
5. let MATCH = PACKAGE_IMPORTS_RESOLVE(X, pathToFileURL(SCOPE),
@@ -436,7 +436,7 @@ LOAD_PACKAGE_EXPORTS(X, DIR)
436436
return.
437437
3. Parse DIR/NAME/package.json, and look for "exports" field.
438438
4. If "exports" is null or undefined, return.
439-
5. If `--experimental-require-module` is enabled
439+
5. If `--no-require-module` is not enabled
440440
a. let CONDITIONS = ["node", "require", "module-sync"]
441441
b. Else, let CONDITIONS = ["node", "require"]
442442
6. let MATCH = PACKAGE_EXPORTS_RESOLVE(pathToFileURL(DIR/NAME), "." + SUBPATH,

doc/node.1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ Disable top-level await keyword support in REPL.
216216
.It Fl -no-experimental-sqlite
217217
Disable the experimental node:sqlite module.
218218
.
219+
.It Fl -no-require-module
220+
Disable support for loading ECMAScript modules with require().
221+
.
219222
.It Fl -no-strip-types
220223
Disable type-stripping for TypeScript files.
221224
.

lib/internal/bootstrap/node.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ const features = {
283283
return binding.hasCachedBuiltins();
284284
},
285285
get require_module() {
286-
return getOptionValue('--experimental-require-module');
286+
return getOptionValue('--require-module');
287287
},
288288
get quic() {
289289
// TODO(@jasnell): When the implementation is updated to support Boring,

lib/internal/modules/cjs/loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,7 @@ function wrapSafe(filename, content, cjsModuleInstance, format) {
16851685
} else {
16861686
// For modules being loaded by `require()`, if require(esm) is disabled,
16871687
// don't try to reparse to detect format and just throw for ESM syntax.
1688-
shouldDetectModule = getOptionValue('--experimental-require-module');
1688+
shouldDetectModule = getOptionValue('--require-module');
16891689
}
16901690
}
16911691
const result = compileFunctionForCJSLoader(content, filename, false /* is_sea_main */, shouldDetectModule);
@@ -1884,7 +1884,7 @@ Module._extensions['.js'] = function(module, filename) {
18841884
const { source, format: loadedFormat } = loadSource(module, filename, format);
18851885
// Function require shouldn't be used in ES modules when require(esm) is disabled.
18861886
if ((loadedFormat === 'module' || loadedFormat === 'module-typescript') &&
1887-
!getOptionValue('--experimental-require-module')) {
1887+
!getOptionValue('--require-module')) {
18881888
const err = getRequireESMError(module, pkg, source, filename);
18891889
throw err;
18901890
}

lib/internal/modules/esm/loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ class ModuleLoader {
299299
*/
300300
importSyncForRequire(mod, filename, source, isMain, parent) {
301301
const url = pathToFileURL(filename).href;
302-
if (!getOptionValue('--experimental-require-module')) {
302+
if (!getOptionValue('--require-module')) {
303303
throw new ERR_REQUIRE_ESM(url, true);
304304
}
305305

@@ -489,7 +489,7 @@ class ModuleLoader {
489489
}
490490

491491
if (formatFromLoad === 'module' || formatFromLoad === 'module-typescript') {
492-
if (!getOptionValue('--experimental-require-module')) {
492+
if (!getOptionValue('--require-module')) {
493493
throw new ERR_REQUIRE_ESM(url, true);
494494
}
495495
}

lib/internal/modules/esm/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function initializeDefaultConditions() {
7575
const userConditions = getOptionValue('--conditions');
7676
const noAddons = getOptionValue('--no-addons');
7777
const addonConditions = noAddons ? [] : ['node-addons'];
78-
const moduleConditions = getOptionValue('--experimental-require-module') ? ['module-sync'] : [];
78+
const moduleConditions = getOptionValue('--require-module') ? ['module-sync'] : [];
7979
defaultConditions = ObjectFreeze([
8080
'node',
8181
'import',

lib/internal/modules/helpers.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ function initializeCjsConditions() {
8484
...addonConditions,
8585
...userConditions,
8686
];
87-
if (getOptionValue('--experimental-require-module')) {
87+
if (getOptionValue('--require-module')) {
8888
cjsConditionsArray.push('module-sync');
8989
}
9090
ObjectFreeze(cjsConditionsArray);

src/node_options.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,17 +487,23 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
487487
kAllowedInEnvvar,
488488
true);
489489
AddOption("--experimental-print-required-tla",
490-
"Print pending top-level await. If --experimental-require-module "
490+
"Print pending top-level await. If --require-module "
491491
"is true, evaluate asynchronous graphs loaded by `require()` but "
492492
"do not run the microtasks, in order to to find and print "
493493
"top-level await in the graph",
494494
&EnvironmentOptions::print_required_tla,
495495
kAllowedInEnvvar);
496-
AddOption("--experimental-require-module",
496+
AddOption("--require-module",
497497
"Allow loading synchronous ES Modules in require().",
498498
&EnvironmentOptions::require_module,
499499
kAllowedInEnvvar,
500500
true);
501+
AddOption("--experimental-require-module",
502+
"Legacy alias for --require-module",
503+
&EnvironmentOptions::require_module,
504+
kAllowedInEnvvar,
505+
true);
506+
Implies("--experimental-require-module", "--require-module");
501507
AddOption("--diagnostic-dir",
502508
"set dir for all output files"
503509
" (default: current working directory)",

0 commit comments

Comments
 (0)