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

后端 未结 10 1940
南笙
南笙 2021-01-31 01:14

I have a problem with eslint, it gives me [Parsing Error The keyword import is reserve] this is only occur in sublime, in atom editor work well. I have eslint

.eslintr

相关标签:
10条回答
  • 2021-01-31 01:56

    Not sure about it but try to rename your file to .eslintrc and just use

    {
      "extends": "airbnb",
      "plugins": ["react"]
    };
    

    Also be sure you have the required packages installed. github.com/airbnb/javascript

    0 讨论(0)
  • 2021-01-31 01:57

    I found this issue while creating the vue project (Used Editor: Visual Code)

    Install babel-eslint package -> npm install babel-eslint

    Create the .eslintrc.js file and add below code

    module.exports = { root: true, parserOptions: { 'sourceType': 'module', parser: 'babel-eslint'
    } }

    => npm run serve, that error will be resolved like magic.

    0 讨论(0)
  • 2021-01-31 02:00

    Based on @Manohar Reddy Poreddy answer, if you are also using Prettier in VSCode, your .eslintrc.js file should look like:

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

    };

    0 讨论(0)
  • 2021-01-31 02:01

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

    The issue is seen with new react app, and in Visual 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.

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