nodejs / nodejs/node

Indirectly static import cjs with error will cause an uncaughtException

Open
#51,603 15 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

confirmed-bug module
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

Version

v20.10.0

Platform

No response

Subsystem

No response

What steps will reproduce the bug?
// ./main.mjs
process.on('uncaughtException', ()=>console.log('uncaught'));
try {
    await import(`data:text/javascript,
        import "data:text/javascript,console.log('before')";
        import "${import.meta.url}.cjs";
    `);
}
catch { console.log('caught'); }
// ./main.mjs.cjs
throw Error('abc');
How often does it reproduce? Is there a required condition?

every time

What is the expected behavior? Why is that the expected behavior?
before
caught

same with dynamic await import('./main.mjs.cjs') directly or indirectly.

also intuitive.

What do you see instead?
before
uncaught

and the wrapper dynamic import promise will be forever pending

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

Start by running the reproducer in main.mjs with the adjacent main.mjs.cjs file, and inspect how dynamic imports handle errors from indirectly imported CommonJS modules. The fix is done when the example prints before and caught, does not emit uncaught, and the wrapper import promise settles.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.