Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Description
Before You File a Documentation Request Please Confirm You Have Done The Following...
- I have looked for existingopen or closed documentation requests that match my proposal.
- I haveread the FAQ and my problem is not listed.
Suggested Changes
node 23 now supportsrequire(esm)
(unflagged), soTS 5.8 now won't always error whenrequire()
ing an ESM from CJS. That means that any upstream code using top level await ("TLA") (see also the term "async module") will cause the program to fail at runtime, whichwon't be validated at all by TS. Therefore, projects wanting to take advantage ofrequire(esm)
to migrate CJS to ESM will want to ban TLA from appearing in their application's ESM. Similarly, libraries publishing ESM intended to be possible torequire()
must also not use TLA.
There are also times where you would want to use TLA (for example, top level of node js CLI scripts).
Let's provide an example in no-restricted-syntax of how to ban TLA if people want to for their projects.
Here's the config (playground):
{"no-restricted-syntax": ["warn", {"selector":"AwaitExpression:not(:matches(FunctionExpression AwaitExpression, ArrowFunctionExpression AwaitExpression, FunctionDeclaration AwaitExpression))","message":"TLA makes it impossible to `require()` this module or any of its downstream dependencies." } ]}
Affected URL(s)
https://typescript-eslint.io/troubleshooting/faqs/general/#how-can-i-ban-specific-language-feature
Additional Info
No response