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.

Bug: warning about using async await outside function: nodejs16 project

See original GitHub issue

Environment

Node version: 16.13.1 npm version: 8.1.2 Local ESLint version: 8.5.0 Global ESLint version: 8.5.0 Operating System: Linux(zorinoslite16, ubuntu 20.04 based)

What parser are you using?

Default (Espree)

What did you do?

Configuration

package.json: "type": "module",

eslintrc.json: `{ “env”: { “node”: true, “es2021”: true }, “extends”: “eslint:recommended”, “parserOptions”: { “ecmaVersion”: 12, “sourceType”: “module” }, “rules”: {

}

}`

jsconfig.json { "compilerOptions": { "target": "es2021", "module": "es2020", }, "exclude": [ "dist/", "node_modules", "**/node_modules/*", ".vscode/", ] }

const express = require('express')

const { default: express } = await import('express') // Parsing error
.....
await runtime.init() // Parsing error
app.listen(port, () =>
	console.log(`Porta ${port} (${process.env.NODE_ENV})`),
)

What did you expect to happen?

a warning about using require() on esmodule / non-commonjs nodejs v16 project

and no warning about using async await outside functon in a nodejs project “Parsing error: Cannot use keyword ‘await’ outside an async function eslint”

What actually happened?

Eslint didint acuse anything about using require

Eslint acuse Parsing error: Cannot use keyword ‘await’ outside an async function

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

No babel, no other parser

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aladdin-addcommented, Dec 21, 2021

i believe latest es env to use is es2021 right?

looks like that way - es2022 does not have new vars.

Re the require, you could remove node: true in the envs, or config like eslint-plugin-node

1reaction
aladdin-addcommented, Dec 20, 2021

you’ll need to set ecmaVersion: 2022/13 to use TLA.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using await outside of an async function - Stack Overflow
This makes a quick function with async where you can use await. It saves you the need to make an async function which...
Read more >
Async Await in Node.js - How to Master it? - Blog - RisingStack
Learn how to use async await in Node.js (async functions) to simplify your callback or Promise based application.
Read more >
Javascript Promises, Async and Await tips and tricks
How to work with asynchronous functions. To fix the previous error, we have to change the readConfig function so it uses callbacks to...
Read more >
Don't get burned by missing await Calls for Async Code in ...
In this post I'll discuss a nasty bug I ran into with my code, ... with a warning in that async call is...
Read more >
Top-level await is available in Node.js modules - Stefan Judis
js scripts handle many tasks in my projects. There has been one tiny annoyance, though. When dealing with asynchronous functionality such as ...
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