-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Parsing error: Cannot use keyword 'await' outside an async function #1548
Parsing error: Cannot use keyword 'await' outside an async function #1548
Comments
Typically standard doesn't enable this type of support until it is in stage 4 (https://github.com/standard/standard#how-do-i-use-experimental-javascript-es-next-features). |
Regarding Node.js support, it has been supported prior to 14.8.0, but just behind a command line flag. Even with it unflagged, Node.js still documents the support has experimental, of course (https://nodejs.org/dist/latest-v14.x/docs/api/esm.html#esm_experimental_top_level_await). I'm not sure why it is still marked as experimental unless they are waiting for it to enter either Stage 4 or it become part of the standard. |
Thanks @dougwilson - this is fair enough and it's one of the downsides to not putting experimental features behind flags. My only counterpoint here is for the sake of pragmatism: if it's not behind a flag, people will use it without checking whether it's experimental and while this isn't in any way the linters fault, the linter may be blamed regardless. |
To clarify, I am not a member of this project and cannot make decisions etc. I was just trying to help by connecting your question to the project's written policy. |
Thanks for the suggestion @davidmarkclements and for the helpful discussion @dougwilson. Unfortunately, there's not much we can do to easily enable support for this. The language parser used by ESLint has a policy of not supporting features until Stage 4. So this is not solvable unless we decide to start shipping the This issue will be fixed once the feature enters Stage 4. |
Thanks @dougwilson and thanks @feross for a useful discussion ✌️ |
Hey folks I'm using standard to lint some Node 16 ESM files and I'm having an issue with TLA. Any solutions? |
@Ethan-Arrowood I'm ignoring the files containing top-level // package.json
"standard": {
"ignore": [
"**/the-filename.js"
],
} |
Top level await has been stage 4 for a while, is there any fix? |
@extremeheat You can track ESLint progress here: eslint/eslint#14632 |
Hopefully this is happening soon! 🎉 |
With the current code, we can't upgrade to I guess we could release |
With AWS Lambda now supporting top level await (https://aws.amazon.com/blogs/compute/using-node-js-es-modules-and-top-level-await-in-aws-lambda/) I imagine a lot more will run into this parsing error. It looks like |
@willfarrell you can follow Standard 17 (which uses ESLint 8) progress here: standard/eslint-config-standard#208 |
Prerelease Would love if you could all test this and report back here if this is still an issue 🙏 We'll reopen this if its still an issue. |
@voxpelli Something wrong is not right // main.js
await new Promise(resolve => resolve()) $ standard --version
17.0.0-0
$ eslint --version
v8.8.0
$ standard .\main.js
standard: Use JavaScript Standard Style (https://standardjs.com)
.\main.js:1:1: Parsing error: Cannot use keyword 'await' outside an async function (null) Furthermore, VSCode ( |
@NemoStein Right, thanks, I'll reopen. Have you tested in plain ESLint 8 and seen if it works there? Maybe we need to explicitly allow it? In regards to the VSCode extension, that one needs an update, I highlighted that in standard/eslint-config-standard#208 now 🙏 |
just had a quick look and standard 17 doesn't support class instance fields, either (which eslint 8 does) class Test {
something = 1
}
export default Test
|
@voxpelli Ok, here goes my 2 cents. // .eslintrc.js
module.exports = {
env: {
es2021: true,
},
parserOptions: {
ecmaVersion: 'latest', // <--- This line!!!
sourceType: 'module'
}
} // main.js
await new Promise(resolve => resolve()) With $ eslint .\main.js
$ Without $ eslint .\main.js
.\main.js
1:1 error Parsing error: Cannot use keyword 'await' outside an async function
✖ 1 problem (1 error, 0 warnings)
$ |
@NemoStein Yeah, I arrived at the same conclusion, will merge and release standard/eslint-config-standard#212 when another maintainer gives me a review 👍 |
@NemoStein @75lb We just released Unless standard/eslint-config-standard-jsx#43 overrides that fix, then it should work now, else we'll try to get a fix in for that issue and releases a Both me and @divlo needs some sleep now 😅 |
Sadly it does, but I can confirm that updating the |
|
What version of this package are you using?
14.3.4
What operating system, Node.js, and npm version?
Node: 14.13.0
npm: 6.14.8
OS: macOS Catalina 10.15.5
What happened?
Given code:
Output is:
What did you expect to happen?
Top-level await
is a stage 3 proposal (see https://tc39.es/proposal-top-level-await/) but is enabled by default in from Node 14.8.0 (see https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V14.md#2020-08-11-version-1480-current-codebytere).This is going to mean that linting with apps written for Node 14+ will be problematic, as top-level await is bound to be used.
Since Node 14 is becoming Active LTS in a few weeks I think TLA should pass linting
Are you willing to submit a pull request to fix this bug?
yes
The text was updated successfully, but these errors were encountered: