node
node copied to clipboard
Experimental require of circular ESM graph stack overflow
Version
v22.1.0
Platform
macos
Subsystem
modules
What steps will reproduce the bug?
$ cat left.mjs
import {} from './right.mjs';
$ cat right.mjs
import {} from './left.mjs';
$ node left.mjs
# (nothing)
$ cat main.cjs
require('./left.mjs');
$ node --experimental-require-module main.cjs
node:fs:441
function readFileSync(path, options) {
^
RangeError: Maximum call stack size exceeded
at readFileSync (node:fs:441:22)
at getSourceSync (node:internal/modules/esm/load:85:14)
at defaultLoadSync (node:internal/modules/esm/load:201:32)
at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:363:24)
at new ModuleJobSync (node:internal/modules/esm/module_job:307:32)
at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:404:11)
at new ModuleJobSync (node:internal/modules/esm/module_job:307:32)
at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:404:11)
at new ModuleJobSync (node:internal/modules/esm/module_job:307:32)
at ModuleLoader.getModuleJobForRequire (node:internal/modules/esm/loader:404:11)
Node.js v22.1.0
How often does it reproduce? Is there a required condition?
It reproduces consistently.
What is the expected behavior? Why is that the expected behavior?
Circular imports are well-defined in the specification and should work correctly.
What do you see instead?
Stack overflow
Additional information
No response
@joyeecheung #51977 thanks!
@nodejs/loaders
Thanks for reporting it, fix in https://github.com/nodejs/node/pull/52868