-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
As part of the standard experimental feature graduation policy, when we unflagged require(esm) we moved the experimental warning to be emitted when require() is actually used to load ESM, which previously was an error. However, some packages in the ecosystem have already being using try-catch to load require(esm) to e.g. resolve optional dependency, and emitting warning from there instead of throwing directly could break the CLI output. To reduce the disruption for releases, as a compromise, this patch skips the warning if require(esm) comes from node_modules, where users typically don't have much control over the code. This warning will be eventually removed when require(esm) becomes stable. This patch was originally intended for the LTS releases, though it seems there's appetite for it on v23.x as well so it's re-targeted to the main branch. PR-URL: nodejs#55960 Refs: nodejs#55217 Refs: nodejs#52697 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
// This checks the experimental warning for require(esm) is disabled when the | ||
// require() comes from node_modules. | ||
require('../common'); | ||
const { spawnSyncAndAssert } = require('../common/child_process'); | ||
const fixtures = require('../common/fixtures'); | ||
|
||
const warningRE = /Support for loading ES Module in require\(\)/; | ||
|
||
// The fixtures are placed in a directory that includes "node_modules" in its name | ||
// to check false negatives. | ||
|
||
// require() in non-node_modules -> esm in node_modules should warn. | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[fixtures.path('es-modules', 'test_node_modules', 'require-esm.js')], | ||
{ | ||
trim: true, | ||
stderr: warningRE, | ||
stdout: 'world', | ||
} | ||
); | ||
|
||
// require() in non-node_modules -> require() in node_modules -> esm in node_modules | ||
// should not warn. | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[fixtures.path('es-modules', 'test_node_modules', 'require-require-esm.js')], | ||
{ | ||
trim: true, | ||
stderr: '', | ||
stdout: 'world', | ||
} | ||
); | ||
|
||
// Import in non-node_modules -> require() in node_modules -> esm in node_modules | ||
// should not warn. | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[fixtures.path('es-modules', 'test_node_modules', 'import-require-esm.mjs')], | ||
{ | ||
trim: true, | ||
stderr: '', | ||
stdout: 'world', | ||
} | ||
); | ||
|
||
// Import in non-node_modules -> import in node_modules -> | ||
// require() in node_modules -> esm in node_modules should not warn. | ||
spawnSyncAndAssert( | ||
process.execPath, | ||
[fixtures.path('es-modules', 'test_node_modules', 'import-import-require-esm.mjs')], | ||
{ | ||
trim: true, | ||
stderr: '', | ||
stdout: 'world', | ||
} | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.