Skip to content

Experimental require of circular ESM graph stack overflow #52864

Closed
@laverdet

Description

@laverdet

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    loadersIssues and PRs related to ES module loaders

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions