【问题标题】:How to fix 'Unexpected Token' when I work with ESLint?使用 ESLint 时如何修复“意外令牌”?
【发布时间】:2019-12-23 15:21:46
【问题描述】:
  26 | 
  27 | class DefaultLayout extends Component {
> 28 |   loading = () => <div className="animated fadeIn pt-1 text-center">Loading...</div>;
     |                   ^

ESLint 正在为打开的&lt;div&gt; 标记返回解析错误(意外标记)。我错过了什么? JSX 中不允许使用普通的 HTML 属性吗? (div 似乎工作正常)

我尝试通过对 eslint、babel 插件和 webpack 配置的大量配置来修复它们。但我无法修复它。

{
  "env": {
    "browser": true,
    "es6": true,
    "commonjs": true,
    "node": true,
    "jest": true
  },
  "extends": [
    "airbnb"
  ],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parser": "babel-eslint",
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true,
      "modules": true,
      "experimentalObjectRestSpread": true
    },
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "plugins": [
    "react"
  ],
  "rules": {
    "react/jsx-filename-extension": ["warn", { "extensions": [".js", ".jsx"] }],
    "react/jsx-curly-newline": ["warn", { "multiline": "consistent", "singleline": "consistent" }],
    "react/state-in-constructor": ["warn", "always"],
    "react/jsx-props-no-spreading": ["warn", {
      "html": "ignore",
      "custom": "enforce",
      "exceptions": ["Image", "img"]
      }],
      "import/no-named-as-default": "off",
      "import/no-named-as-default-member": "off",
      "max-len": ["warn", { "code": 120 }],
      "import/no-extraneous-dependencies": ["error", {"devDependencies": true, "packageDir": "./"}],
      "react/destructuring-assignment": [0],
      "react/prop-types": [0],
      "react/no-array-index-key": "warn"
    }
  }

拜托,你能帮帮我吗?

【问题讨论】:

  • 这个项目是用 CRA (Create-react-app) 开始的,但我运行 (eject)。
  • 你的 eslint-config-react-app 包中有 parser: 'babel-eslint' 吗?它应该在 index.js 文件中。
  • 我的 index.js 中没有 'babel-eslint',我有 parser": "babel-eslint" 在 .eslintrc.json 中

标签: reactjs babeljs create-react-app eslint


【解决方案1】:

我通过删除 Prettier 扩展解决了我的问题。

【讨论】:

    猜你喜欢
    • 2020-10-19
    • 2019-04-03
    • 2020-09-06
    • 2021-10-08
    • 1970-01-01
    • 2019-08-29
    • 1970-01-01
    • 2022-01-02
    • 2019-11-22
    相关资源
    最近更新 更多