Repository navigation
Closed
Labels
confirmed-bugIssues and PRs for confirmed bugs.esmIssues and PRs related to the ECMAScript Modules implementation.loadersIssues and PRs related to ES module loaders.
Description
Version
23.0.0
Platform
Darwin Nics-MacBook-Air.local 23.6.0 Darwin Kernel Version 23.6.0: Mon Jul 29 21:16:46 PDT 2024; root:xnu-10063.141.2~1/RELEASE_ARM64_T8112 arm64
Subsystem
No response
What steps will reproduce the bug?
EDIT: See in #55500 (comment) for a minimal reproduction
- Clone https://github.com/nicolo-ribaudo/babel/tree/node-bug
- Run
yarn install - Run
make use-esm - Run
(cd ./packages/babel-core/test/fixtures/async/plugin-mjs-tla-native; node ../../babel-compile-async.mjs ./input.js)
How often does it reproduce? Is there a required condition?
I don't have a minimal reproduction
What is the expected behavior? Why is that the expected behavior?
To not tell me to open a bug report :P
What do you see instead?
(node:69972) ExperimentalWarning: Support for loading ES Module in require() is an experimental feature and might change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
node:internal/assert:11
throw new ERR_INTERNAL_ASSERTION(message);
^
Error [ERR_INTERNAL_ASSERTION]: [BABEL]: A require()-d module that is imported again must be evaluated. Status = 2
This is caused by either a bug in Node.js or incorrect usage of Node.js internals.
Please open an issue with this stack trace at https://github.com/nodejs/node/issues
(While processing: /Users/nic/Documents/dev/github.com/babel/babel/packages/babel-core/test/fixtures/async/plugin-mjs-tla-native/plugin.js)
at assert (node:internal/assert:11:11)
at ModuleJobSync.run (node:internal/modules/esm/module_job:358:5)
at onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:42)
at async loadMjsFromPath (file:///Users/nic/Documents/dev/github.com/babel/babel/packages/babel-core/lib/config/files/module-types.js:45:12) {
code: 'ERR_INTERNAL_ASSERTION'
}
Additional information
I don't think I'm using Node.js internals.
cc @joyeecheung
Metadata
Metadata
Assignees
Labels
confirmed-bugIssues and PRs for confirmed bugs.esmIssues and PRs related to the ECMAScript Modules implementation.loadersIssues and PRs related to ES module loaders.
Activity
nicolo-ribaudo commentedon Oct 23, 2024
The relevant code is in
packages/babel-core/lib/config/files/module-types.js.What is going on is that:
loadCodeDefault, we go in theauto .jsbranchloadCjsDefault, whichrequiresplugin.jscatchinsideloadCodeDefault,async ??= yield* isAsync()istrueto we suppress the errorloadMjsFromPathin theauto .mjsbranchloadMjsFromPathcallsimport_(url), which callsimport(url)However, a minimal reproduction of
try/catcharoundrequire()falling back toimport()does not trigger the assertion.nicolo-ribaudo commentedon Oct 23, 2024
Minimal reproduction:
avivkeller commentedon Oct 23, 2024
avivkeller commentedon Oct 23, 2024
Failing assertion:
node/lib/internal/modules/esm/module_job.js
Line 358 in 7b5d660
joyeecheung commentedon Oct 23, 2024
Thanks for reporting it, fix in #55502
module: allow ESM that failed to be required to be re-imported
module: allow ESM that failed to be required to be re-imported
module: allow ESM that failed to be required to be re-imported
module: allow ESM that failed to be required to be re-imported
module: allow ESM that failed to be required to be re-imported
ci: pin Node to 22 to avoid a Node 24 require(esm) race in Vitest