eslint: error Parsing error: The keyword 'const' is reserved

后端 未结 6 1158
余生分开走
余生分开走 2020-12-12 15:04

I am getting this error from ESLint:

error  Parsing error: The keyword \'const\' is reserved

from

相关标签:
6条回答
  • 2020-12-12 15:42

    I had this same problem with this part of my code:

    const newComment = {
        dishId: dishId,
        rating: rating,
        author: author,
        comment: comment
    };
    newComment.date = new Date().toISOString();
    

    Same error, const is a reserved word.

    The thing is, I made the .eslintrc.js from the link you gave in the update and still got the same error. Also, I get an parsing error in the .eslintrc.js: Unexpected token ':'.

    Right in this part:

    "env": {
    "browser": true,
    "node": true,
    "es6": true
    },
    
    ...
    
    0 讨论(0)
  • 2020-12-12 15:43

    you also can add this inline instead of config, just add it to the same file before you add your own disable stuff

    /* eslint-env es6 */
    /* eslint-disable no-console */
    

    my case was disable a file and eslint-disable were not working for me alone

    /* eslint-env es6 */
    /* eslint-disable */
    
    0 讨论(0)
  • 2020-12-12 15:48

    I used .eslintrc.js and I have added following code.

    module.exports = {
        "parserOptions": {
            "ecmaVersion": 6
        }
    };
    
    0 讨论(0)
  • 2020-12-12 15:57

    ESLint defaults to ES5 syntax-checking. You'll want to override to the latest well-supported version of JavaScript.

    Try adding a .eslintrc file to your project. Inside it:

    {
        "parserOptions": {
            "ecmaVersion": 2017
        },
    
        "env": {
            "es6": true
        }
    }
    

    Hopefully this helps.

    EDIT: I also found this example .eslintrc which might help.

    0 讨论(0)
  • 2020-12-12 16:04

    If using Visual Code one option is to add this to the settings.json file:

    "eslint.options": {
        "useEslintrc": false,
        "parserOptions": {
            "ecmaVersion": 2017
        },
        "env": {
            "es6": true
        }
    }
    
    0 讨论(0)
  • 2020-12-12 16:07

    In my case, it was unable to find the .eslintrc file so I copied from node_modules/.bin to root.

    0 讨论(0)
提交回复
热议问题