node `--experimental-require-module` issue with dependency between `pkg-types` and `mlly`
Environment
node: v20.17.0
Reproduction
// test.js
import 'pkg-types'
And run node --experimental-require-module -e 'require("./test.js")'
Describe the bug
pkg-types and mlly are circular dependencies, causing a stack overflow when the --experimental-require-module option is enabled.
Additional context
No response
Logs
❯ node --experimental-require-module -e 'require("./test.js")'
node:fs:570
function openSync(path, flags, mode) {
^
RangeError: Maximum call stack size exceeded
at Object.openSync (node:fs:570:18)
at readFileSync (node:fs:452:35)
at getSourceSync (node:internal/modules/esm/load:85:14)
at defaultLoadSync (node:internal/modules/esm/load:201:32)
at ModuleLoader.getModuleWrapForRequire (node:internal/modules/esm/loader:362:24)
at new ModuleJobSync (node:internal/modules/esm/module_job:276:32)
at ModuleLoader.getModuleWrapForRequire (node:internal/modules/esm/loader:403:11)
at new ModuleJobSync (node:internal/modules/esm/module_job:276:32)
at ModuleLoader.getModuleWrapForRequire (node:internal/modules/esm/loader:403:11)
at new ModuleJobSync (node:internal/modules/esm/module_job:276:32)
Node.js v20.17.0
Thanks for report. I'm aware of this but both ESM and CJS loaders are supposed to support circular dependencies. In fact, the core of Node.js has many of them!
It seems an implementation issue to me with node --experimental-require-module flag..
We can fix it somehow (and as a bonus gain little of loader perf): https://github.com/unjs/mlly/issues/274
it is still a node.js bug..
Fixed in latest v22