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

opike picture opike · Mar 9, 2017 · Viewed 110.7k times · Source

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.

Answer

iamjpg picture iamjpg · Mar 9, 2017

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.