React Project Eslint错误:解析错误:意外字符“ @”

时间:2020-07-18 08:42:21

标签: reactjs decorator eslint

我想在我的react项目中使用装饰器,但有一个错误刚刚显示出来。我已经阅读了很多文档,但这无济于事,这困扰了我很长一段时间。请帮助我。

我的项目使用过:create-react-app + craco + eslint。

我的文件中有一些配置:

package.json:

{
  "name": "xxx",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@craco/craco": "^5.6.4",
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-scripts": "3.4.1"
  },
  "scripts": {
    "start": "craco start",
    "build": "craco build",
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@babel/plugin-proposal-decorators": "^7.10.5",
    "@babel/plugin-proposal-nullish-coalescing-operator": "^7.10.4",
    "@babel/plugin-proposal-optional-chaining": "^7.10.4",
    "@babel/plugin-transform-regenerator": "^7.10.4",
    "@babel/plugin-transform-runtime": "^7.10.5",
    "@commitlint/cli": "^8.1.0",
    "babel-eslint": "10.1.0",
    "cz-conventional-changelog": "^2.1.0",
    "eslint-config-airbnb": "^18.2.0",
    "eslint-plugin-import": "^2.22.0",
    "eslint-plugin-jsx-a11y": "^6.3.1",
    "eslint-plugin-react": "^7.20.3"
  }
}

craco.config.js:

eslint: {
    enable: true /* (default value) */,
    mode: 'file',
  },
  babel: {
    // presets: ['react-app'],
    plugins: [
      '@babel/plugin-transform-runtime',
      [
        '@babel/plugin-proposal-decorators',
        {
          'legacy': true
        }
      ],
      '@babel/plugin-transform-regenerator',
      '@babel/plugin-proposal-optional-chaining',
      '@babel/plugin-proposal-nullish-coalescing-operator'
    ],
  },

.eslintrc.js:

module.exports = {
  root: true,
  env: {
    'es6': true,
    'browser': true,
    'commonjs': true
  },

  extends: ['airbnb', 'react-app'],
  globals: {
    Babel: true,
    React: true
  },
  parserOptions: {
    ecmaVersion: 2020,
    parser: 'babel-eslint',
    sourceType: 'module'
  },

};

0 个答案:

没有答案