Parsing Error The Keyword import is Reserved (SublimeLinter-contrib-eslint)

Spent 30 mins - trying all solutions but dint work, so sharing this one.

The issue is seen with new react app, and in Visual Studio Code, even at this time - Apr 2020.

  1. Create a file .eslintrc.js in the root folder (beside package.json, or beside /src/ directory)
  2. Paste below contents in .eslintrc.js
  3. Restart your editor, like VS Code.
  4. Now I can see real errors, instead of those fake import/export errors.

.eslintrc.js file contents:

module.exports = {
  env: {
    commonjs: true,
    node: true,
    browser: true,
    es6: true,
    jest: true,
  },
  extends: ["eslint:recommended", "plugin:react/recommended"],
  globals: {},
  parser: "babel-eslint",
  parserOptions: {
    ecmaFeatures: {
      jsx: true,
    },
    ecmaVersion: 2018,
    sourceType: "module",
  },
  plugins: ["react", "import", "react-hooks"],
  ignorePatterns: ["node_modules/"],
  rules: {},
  settings: {
    react: {
      version: "latest", // "detect" automatically picks the version you have installed.
    },
  },
};

Hope that helps.


The problem was i had installed eslint globally and locally, causing inconsistencies in SublimeLinter-contrib-eslint. I uninstalled eslint globally and SublimeLinter is working.


The eslint option that solves the "The keyword import is reserved" error is parserOptions.sourceType. Setting it to "module" allows the import keyword to be used.

.eslintrc

{
    "parserOptions": {
        "sourceType": "module"
    }
}

Docs: https://eslint.org/docs/user-guide/configuring#specifying-parser-options


Add this to the root of your .eslintrc.json (formerly .eslintrc)

"parser": "babel-eslint"

and make sure to run:

npm install babel-eslint --save-dev