B
B
Bogdan2020-09-21 20:56:08
JavaScript
Bogdan, 2020-09-21 20:56:08

Eslint Top level await?

Hello, please advise. I use VS Code editor and Node JS 14+. Now Top-Level Await is screwed in the node .
And it is not clear how to configure eslint so that it does not display errors

Parsing error: Cannot use keyword 'await' outside an async function

5f68e716dfd2e336790321.png

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "fastify": "^3.4.1"
  },
  "devDependencies": {
    "@babel/core": "^7.11.6",
    "@babel/eslint-parser": "^7.11.5",
    "@babel/plugin-syntax-top-level-await": "^7.10.4",
    "eslint": "^7.9.0",
    "eslint-config-airbnb-base": "^14.2.0",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-node": "^11.1.0"
  }
}


.eslintrc.cjs
module.exports = {
  parserOptions: {
    ecmaVersion: 2021,
    sourceType: 'module',
    parser: "@babel/eslint-parser"
  }
};


babel.config.json
{
  "plugins": ["@babel/plugin-syntax-top-level-await"]
}


Googled like a solution , but something doesn't work. Maybe I'm connecting the babel plugin incorrectly.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Robur, 2020-09-22
@Robur

Maybe I'm connecting the babel plugin incorrectly.

apparently. And you don't need a plugin, but another parser https://github.com/babel/babel/tree/main/eslint/ba...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question