9

我实际上正在做一个项目,当我在 MacBook 上克隆我的项目时,yarn在 shell 中安装包并atom .打开我的 ATOM。ESLint 有一个“错误”。

例如,对于此代码:

/*
 * Package Import
 */
 import React, { Component } from 'react';
 import PropTypes from 'prop-types';
 import { Link } from 'react-router-dom';
 import classNames from 'classnames';


/*
 * Code
 */
class UserDropdown extends Component {
  /*
   * PropTypes
   */
   static propTypes = {
     ... // Code 
   }


  /*
   * State
   */
   state = {
     ... // Code
   };

  /*
   * Actions
   */
   onLogOut = () => {
     ... // Code
   };

ESLint 告诉我:

Error   ESLint  'propTypes' is not defined. (no-undef)  22:10
Error   ESLint  'state' is not defined. (no-undef)  32:3
Error   ESLint  'onLogOut' is not defined. (no-undef)   52:3

我仍在使用"babel-plugin-transform-class-properties": "^6.24.1",我在我的 brunch-config 中声明了它:

我的早午餐-config.coffee

  plugins:
    babel:
      presets: ['latest', 'react']
      plugins: [
        'transform-class-properties'
        'transform-object-rest-spread'
      ]

我的 .eslintrc

{
  "extends": "airbnb",
  "parser": "babel-eslint",
  "env": {
    "browser": true
  },
  "rules": {
    "brace-style": ["error", "stroustrup"],
    "no-param-reassign": ["error", { "props": false }],
    "no-mixed-operators": ["error", { "allowSamePrecedence": true }],
    "jsx-a11y/no-static-element-interactions": "off",
    "react/jsx-filename-extension": "off",
    "react/forbid-prop-types": "off",
    "react/no-unescaped-entities": "off",
    "linebreak-style": "off"
  },
  "settings": {
    "import/resolver": {
      "node": {
        "paths": ["app/"]
      }
    }
  }
}

还有我的 Packages.json

"devDependencies": {
"auto-reload-brunch": "^2.7.1",
"autoprefixer": "^6.7.7",
"babel-brunch": "^6.1.1",
"babel-eslint": "^7.2.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.24.1",
"babel-resolver": "^1.1.0",
"brunch": "^2.10.9",
"chai": "^3.5.0",
"enzyme": "^2.8.2",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-import-resolver-node": "^0.3.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",

我在两台电脑上工作,在 Linux 上,没关系。那么,有人有想法吗?如果您需要更多代码来理解,我可以发送它。谢谢你哥们!

4

5 回答 5

3

我遇到了同样的问题,这是因为我安装了 ESLint 4。检查您的 package.json 并确保它不是"eslint": "^3.19.0 || ^4.3.0". 我正在使用 create-react-app,但它与 ESLint 4 不兼容:https ://github.com/facebookincubator/create-react-app/issues/2604

于 2017-08-08T11:06:26.090 回答
2

首先,您必须安装 babel-eslint 作为开发依赖项,然后在您的 .eslintrc 文件中添加:

"parser": "babel-eslint"
于 2017-07-25T19:35:08.670 回答
1

升级eslint

npm i -D eslint@latest
于 2018-07-25T09:05:11.363 回答
0

我通过卸载节点、纱线和 npm 解决了我的问题。我使用了最新版本的节点(实际上是 8.2.1,与 npm 和 yarn 相同......)

因此,在安装 Node LTS (6.11.1) 之后,我对 ESLint 没有任何问题,运行良好。

编辑:重新安装纱线(0.27.5)后,这个问题又回来了:思考:

于 2017-07-25T23:12:24.937 回答
0

我使用以下依赖项修复了它:

包.json:

"dependencies": {
"react": "16.8.3",
"react-dom": "16.8.3",
"react-scripts": "2.1.8"
}

我做到了:

yarn
npm install webpack@4.28.3
yarn start

它对我有用!

于 2019-03-25T23:48:46.607 回答