question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a specialized error on top-level await and --module node12

See original GitHub issue

Under node12, a top-level await results in

Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', or 'nodenext', and the 'target' option is set to 'es2017' or higher.

This error message has too much text. We should consider specializing these cases for

  • ES modules < es2022
  • Node modules < nodenext
The module setting '{0}' does not support top-level 'await' expressions. Consider switching to '{1}'.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
weswighamcommented, Oct 15, 2021

TLA is actually allowed in only in esm mode nodenext files, since latest node allows TLA in esm - we have tests to that effect - a specialized error for cjs mode files would be good, though.

0reactions
DanielRosenwassercommented, Apr 29, 2022

Just as a heads up, #46149 is updating the logic here as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - How can I use async/await at the top level?
when a module using top-level await is evaluated, it returns a promise to the module loader (like an async function does), which waits...
Read more >
Top-level await is available in Node.js modules - Stefan Judis
Node.js' top-level await feature is available in ES modules. Find out about three ways to enable it and untangle your code.
Read more >
Node.js 16.x runtime now available in AWS Lambda
The Node.js 16 runtime includes support for ES modules and top-level await that was added to the Node.js 14 runtime in January 2022....
Read more >
Announcing TypeScript 4.7 RC - Microsoft Developer Blogs
This should provide newer ES module functionality from Node.js (like ... TypeScript to a higher target that supports top-level await .
Read more >
Using Top-Level await. Modern Asynchronous JavaScript
When the await keyword was first introduced, it wasn't possible to use it outside of async functions. You've probably encountered the fatal syntax...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found