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

I am getting this error from ESLint:

error  Parsing error: The keyword 'const' is reserved

from this code:

const express = require('express');
const app = express();
const _ = require('underscore');

I've tried removing node_modules and reinstalling all npm packages (as suggested here), but to no avail.


Solution 1:

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.

Solution 2:

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 */

Solution 3:

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

module.exports = {
    "parserOptions": {
        "ecmaVersion": 6
    }
};

Solution 4:

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
    }
}

Solution 5:

Please use this syntax in this file .eslintrc.js. If it doesn't exist then you have to create one. Also, do look for steps on how to install eslint as a dev dependency to your current project first by writing these steps npm install --save-dev eslint then create .eslintrc.js file in the project root.

{
    "parserOptions": {
        "ecmaVersion": 2017
    },

    "env": {
        "es6": true
    }
}