Skip to content

Bad reporting unsettled top-level await #58398

@lwr

Description

@lwr

Version

v23.11.0

Platform

Darwin 24.4.0 Darwin Kernel Version 24.4.0: Fri Apr 11 18:32:05 PDT 2025; root:xnu-11417.101.15~117/RELEASE_ARM64_T8132 arm64

Subsystem

No response

What steps will reproduce the bug?

Files

  • package.json:
    {"type": "module"}
  • test.js:
    export const one = 1;
    export const two = await 2;
    Promise.resolve().then(async () => {
        console.log({...await import(import.meta.url)});
    });

run test.js

How often does it reproduce? Is there a required condition?

100% reproducible

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

Outputs It works: { one: 1, two: 2 }

the async execution code block inside promise then should be executed normally

What do you see instead?

Warning: Detected unsettled top-level await at file:///path/to/test.js:1
export const one = 1;

And the process exited with error code 13.

Additional information

  • It would be related with Top-level await + dynamic import + cyclic import causes "unsettled TLA" error #55468 but they are not the same problem
  • Node 22 passes this test (v22.10.0)
  • Adding simple noop statement workarounds this problem, this is a modified version which can pass the test
    export const one = 1;
    export const two = await 2;
    
    Promise.resolve().then(async () => {
        console.log('It works:', {...await import(import.meta.url)});
    });
    
    void 0; // empty statement do not work
    or even
    export const one = 1;
    export const two = await 2;
    
    void Promise.resolve().then(async () => {
        console.log('It works:', {...await import(import.meta.url)});
    });

I believed that node runtime incorrectly add await to the last statement, that is totally a mistake

export const one = 1;
export const two = await 2;
await Promise.resolve().then(async () => {
    console.log('It works:', {...await import(import.meta.url)});
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions