admin管理员组

文章数量:1201212

Which configuration to use with ESLint to have it accept both code like:

return new Promise(..)

and

async function() {...}

This is used in Node.js

Whatever configuration of ES6 2017.... I keep on having errors like :

'Promise' is not defined no-undef

or

Parsing error: Unexpected token function

Thanks !

Which configuration to use with ESLint to have it accept both code like:

return new Promise(..)

and

async function() {...}

This is used in Node.js

Whatever configuration of ES6 2017.... I keep on having errors like :

'Promise' is not defined no-undef

or

Parsing error: Unexpected token function

Thanks !

Share Improve this question edited Nov 28, 2018 at 17:17 Hunter McMillen 61.5k25 gold badges123 silver badges175 bronze badges asked Nov 28, 2018 at 17:15 DevBabDevBab 8797 silver badges14 bronze badges 3
  • Did you set ecmaVersion to 6? eslint.org/docs/user-guide/… or es6 environment eslint.org/docs/user-guide/configuring#specifying-environments – Jaime Commented Nov 28, 2018 at 17:19
  • This issue looks like it has information that would be useful: github.com/eslint/eslint/issues/9812 – Hunter McMillen Commented Nov 28, 2018 at 17:19
  • with this: "env": { "node": true, "es6": true }, "extends": "eslint:recommended", "parserOptions": { "ecmaVersion": 6 }, I have Parsing error: Unexpected token function – DevBab Commented Nov 28, 2018 at 17:25
Add a comment  | 

2 Answers 2

Reset to default 26

FWIW, eslint needs ES6 specified in the parser AND the environment sections, e.g.

{
    "parserOptions": {
        "ecmaVersion": 9,
        "sourceType": "module",
        "ecmaFeatures": {
            "jsx": true,
            "modules": true
        }
    },
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": "eslint:recommended",
    ...

See https://github.com/eslint/eslint/issues/9812 for a discussion.

Just add this line of comment in the top of the file you are working in

/*eslint no-undef: 0*/

Or you can change the eslint config file (change the rules)

And you are good to go!

Hope this helps!

本文标签: javascriptESlintwhich config for Promise and AsyncStack Overflow