Provide a specialized error on top-level await and --module node12
See original GitHub issueUnder 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:
- Created 2 years ago
- Reactions:2
- Comments:7 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.Just as a heads up, #46149 is updating the logic here as well.