Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 83c3867

Browse filesBrowse files
joyeecheungaduh95
authored andcommitted
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. PR-URL: #60959 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 68fbc0c commit 83c3867
Copy full SHA for 83c3867

10 files changed

+62-38Lines changed: 62 additions & 38 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+37-25Lines changed: 37 additions & 25 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -1137,27 +1137,6 @@ If the ES module being `require()`'d contains top-level `await`, this flag
11371137
allows Node.js to evaluate the module, try to locate the
11381138
top-level awaits, and print their location to help users find them.
11391139

1140-
### `--experimental-require-module`
1141-
1142-
<!-- YAML
1143-
added:
1144-
- v22.0.0
1145-
- v20.17.0
1146-
changes:
1147-
- version:
1148-
- v23.0.0
1149-
- v22.12.0
1150-
- v20.19.0
1151-
pr-url: https://github.com/nodejs/node/pull/55085
1152-
description: This is now true by default.
1153-
-->
1154-
1155-
> Stability: 1.1 - Active Development
1156-
1157-
Supports loading a synchronous ES module graph in `require()`.
1158-
1159-
See [Loading ECMAScript modules using `require()`][].
1160-
11611140
### `--experimental-sea-config`
11621141

11631142
<!-- YAML
@@ -1845,6 +1824,11 @@ added:
18451824
- v22.0.0
18461825
- v20.17.0
18471826
changes:
1827+
- version:
1828+
- REPLACEME
1829+
pr-url: https://github.com/nodejs/node/pull/60959
1830+
description: The flag was renamed from `--no-experimental-require-module` to
1831+
`--no-require-module`, with the former marked as legacy.
18481832
- version:
18491833
- v23.0.0
18501834
- v22.12.0
@@ -1853,11 +1837,9 @@ changes:
18531837
description: This is now false by default.
18541838
-->
18551839

1856-
> Stability: 1.1 - Active Development
1857-
1858-
Disable support for loading a synchronous ES module graph in `require()`.
1840+
> Stability: 3 - Legacy: Use [`--no-require-module`][] instead.
18591841
1860-
See [Loading ECMAScript modules using `require()`][].
1842+
Legacy alias for [`--no-require-module`][].
18611843

18621844
### `--no-experimental-sqlite`
18631845

@@ -1922,6 +1904,34 @@ changes:
19221904
Disables the family autoselection algorithm unless connection options explicitly
19231905
enables it.
19241906

1907+
<a id="--experimental-require-module"></a>
1908+
1909+
### `--no-require-module`
1910+
1911+
<!-- YAML
1912+
added:
1913+
- v22.0.0
1914+
- v20.17.0
1915+
changes:
1916+
- version:
1917+
- REPLACEME
1918+
pr-url: https://github.com/nodejs/node/pull/60959
1919+
description: This flag was renamed from `--no-experimental-require-module`
1920+
to `--no-require-module`.
1921+
- version:
1922+
- v23.0.0
1923+
- v22.12.0
1924+
- v20.19.0
1925+
pr-url: https://github.com/nodejs/node/pull/55085
1926+
description: This is now false by default.
1927+
-->
1928+
1929+
> Stability: 1.2 - Release Candidate
1930+
1931+
Disable support for loading a synchronous ES module graph in `require()`.
1932+
1933+
See [Loading ECMAScript modules using `require()`][].
1934+
19251935
### `--no-strip-types`
19261936

19271937
<!-- YAML
@@ -3531,6 +3541,7 @@ one is included in the list below.
35313541
* `--report-on-signal`
35323542
* `--report-signal`
35333543
* `--report-uncaught-exception`
3544+
* `--require-module`
35343545
* `--require`, `-r`
35353546
* `--secure-heap-min`
35363547
* `--secure-heap`
@@ -4067,6 +4078,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
40674078
[`--experimental-webstorage`]: #--experimental-webstorage
40684079
[`--heap-prof-dir`]: #--heap-prof-dir
40694080
[`--import`]: #--importmodule
4081+
[`--no-require-module`]: #--no-require-module
40704082
[`--no-strip-types`]: #--no-strip-types
40714083
[`--openssl-config`]: #--openssl-configfile
40724084
[`--preserve-symlinks`]: #--preserve-symlinks
Collapse file

‎doc/api/modules.md‎

Copy file name to clipboardExpand all lines: doc/api/modules.md
+4-4Lines changed: 4 additions & 4 deletions
  • Display the source diff
  • Display the rich diff
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,
Collapse file

‎doc/node-config-schema.json‎

Copy file name to clipboardExpand all lines: doc/node-config-schema.json
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,9 @@
343343
}
344344
]
345345
},
346+
"require-module": {
347+
"type": "boolean"
348+
},
346349
"secure-heap": {
347350
"type": "number"
348351
},
Collapse file

‎doc/node.1‎

Copy file name to clipboardExpand all lines: doc/node.1
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ Disable top-level await keyword support in REPL.
213213
.It Fl -no-experimental-sqlite
214214
Disable the experimental node:sqlite module.
215215
.
216+
.It Fl -no-require-module
217+
Disable support for loading ECMAScript modules with require().
218+
.
216219
.It Fl -no-strip-types
217220
Disable type-stripping for TypeScript files.
218221
.
Collapse file

‎lib/internal/bootstrap/node.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js
+1-1Lines 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
};
289289

Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ function wrapSafe(filename, content, cjsModuleInstance, format) {
17371737
} else {
17381738
// For modules being loaded by `require()`, if require(esm) is disabled,
17391739
// don't try to reparse to detect format and just throw for ESM syntax.
1740-
shouldDetectModule = getOptionValue('--experimental-require-module');
1740+
shouldDetectModule = getOptionValue('--require-module');
17411741
}
17421742
}
17431743
const result = compileFunctionForCJSLoader(content, filename, false /* is_sea_main */, shouldDetectModule);
@@ -1936,7 +1936,7 @@ Module._extensions['.js'] = function(module, filename) {
19361936
const { source, format: loadedFormat } = loadSource(module, filename, format);
19371937
// Function require shouldn't be used in ES modules when require(esm) is disabled.
19381938
if ((loadedFormat === 'module' || loadedFormat === 'module-typescript') &&
1939-
!getOptionValue('--experimental-require-module')) {
1939+
!getOptionValue('--require-module')) {
19401940
const err = getRequireESMError(module, pkg, source, filename);
19411941
throw err;
19421942
}
Collapse file

‎lib/internal/modules/esm/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/loader.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ class ModuleLoader {
305305
*/
306306
importSyncForRequire(mod, filename, source, isMain, parent) {
307307
const url = pathToFileURL(filename).href;
308-
if (!getOptionValue('--experimental-require-module')) {
308+
if (!getOptionValue('--require-module')) {
309309
throw new ERR_REQUIRE_ESM(url, true);
310310
}
311311

@@ -495,7 +495,7 @@ class ModuleLoader {
495495
}
496496

497497
if (formatFromLoad === 'module' || formatFromLoad === 'module-typescript') {
498-
if (!getOptionValue('--experimental-require-module')) {
498+
if (!getOptionValue('--require-module')) {
499499
throw new ERR_REQUIRE_ESM(url, true);
500500
}
501501
}
Collapse file

‎lib/internal/modules/esm/utils.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/utils.js
+1-1Lines 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',
Collapse file

‎lib/internal/modules/helpers.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/helpers.js
+1-1Lines 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);
Collapse file

‎src/node_options.cc‎

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.