1

I am using vscode with the ESLint extension.

I have node 16 installed and my eslint config is as follows...

{
    "env": {
        "node": true,
        "commonjs": true,
        "es2021": true
    },
    "extends": "eslint:recommended",
    "overrides": [
    ],
    "parserOptions": {
        "ecmaVersion": "latest"
    },
    "rules": {
        "no-unused-vars": "off"
    }
}

I have the following javascript code...

async function func1 (val) {
  console.log(val);
}

await func1("blah");

The last line of code is giving the error...

Parsing error: Unexpected token func1

Why is this error occuring?

Scorb
  • 1,654
  • 13
  • 70
  • 144

1 Answers1

-1

If you are using ESLint >= 8.0, in your config file, replace "es2021" with "es2022":

{
    "env": {
        "node": true,
        "commonjs": true,
        "es2022": true
    },
    "extends": "eslint:recommended",
    "overrides": [
    ],
    "parserOptions": {
        "ecmaVersion": "latest"
    },
    "rules": {
        "no-unused-vars": "off"
    }
}

The reason is that you are using top-level await syntax, which was finalized in ES2022: https://eslint.org/blog/2021/10/eslint-v8.0.0-released/#highlights.

GOTO 0
  • 42,323
  • 22
  • 125
  • 158