Reputation: 10102
i am using top-level await
in my nodejs module
You can use the
await
keyword on its own (outside of an async function) within a JavaScript module.
Files ending with
.js
are loaded as ES modules when the nearest parentpackage.json
file contains a top-level field"type"
with a value of"module"
$ jq -r '.type' package.json
module
$ node --version
v16.14.2
$ npm --version
8.7.0
$ jq -r '.devDependencies.eslint' package.json
8.12.0
when i run eslint, which should have a support for top-level await
, i get the error
Parsing error: Cannot use keyword 'await' outside an async function
how do i make eslint honor top-level await
?
Upvotes: 10
Views: 3174
Reputation: 47682
Make sure that:
ecmaVersion
should be 2022
or "latest"
, and sourceType
should be "module"
(ESLint does not respect the "type": "module"
setting in package.json
files).Next time you have a question about ESLint, please, show your ESLint configuration (typically .eslintrc.json
or .eslintrc.yml
) to get more specific advice.
Upvotes: 24