pkg-types icon indicating copy to clipboard operation
pkg-types copied to clipboard

node `--experimental-require-module` issue with dependency between `pkg-types` and `mlly`

Open sxzz opened this issue 1 year ago • 2 comments

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

sxzz avatar Aug 24 '24 10:08 sxzz

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..

pi0 avatar Aug 24 '24 10:08 pi0

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..

pi0 avatar Aug 24 '24 10:08 pi0

Fixed in latest v22

sxzz avatar Sep 25 '24 12:09 sxzz