nodejs / nodejs/node

`esm_loader` should use a primordial to get `cwd`

Open
#44,742 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

loaders never-stale
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

Version

v18.9.0

Platform

Linux vhost1 5.18.10-76051810-generic #202207071639~1657252310~22.04~7d5e891 SMP PREEMPT_DYNAMIC Fri J x86_64 x86_64 x86_64 GNU/Linux

Subsystem

esm_loader

What steps will reproduce the bug?
process.cwd = () => {
    (async () => {
        await import('.');
    })();
};

await import('.');
How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior?

No RangeErrors.

What do you see instead?
Exception in PromiseRejectCallback:
node:internal/modules/esm/resolve:1110
  };

RangeError: Maximum call stack size exceeded
Exception in PromiseRejectCallback:
node:internal/modules/esm/loader:163
      const output = await hook(arg0, meta.context, nextNextHook);
Additional information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided reproduction on Node.js v18.9.0, then inspect node:internal/modules/esm/resolve.js and node:internal/modules/esm/loader.js at the stack-trace locations. Trace how esm_loader obtains cwd and update it to use the requested primordial; done means the reproduction completes without RangeErrors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.