eslint - 无法加载插件“@typescript-eslint”

CCC*_*CCC 6 typescript reactjs eslint

当我尝试通过以下方式运行应用程序时npm start

Failed to load plugin '@typescript-eslint' declared in '.eslintrc.json': Class extends value undefined is not a constructor or null
Run Code Online (Sandbox Code Playgroud)

为什么会发生这种情况以及如何解决?

eslintrc.json

{
  "env": {
    "browser": true,
    "es2021": true
  },
  "extends": ["plugin:react/recommended", "airbnb"],
  "parser": "@typescript-eslint/parser",
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [".ts", ".tsx"],
        "moduleDirectory": ["src", "node_modules"]
      }
    }
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "plugins": ["react", "@typescript-eslint"],
  "rules": {
    "no-console": "off"
  }
}
Run Code Online (Sandbox Code Playgroud)

包.json

  "devDependencies": {
    "@babel/core": "^7.16.5",
    "@babel/preset-env": "^7.16.5",
    "@types/react-dom": "^17.0.11",
    "@types/react-router-dom": "^5.3.2",
    "@types/react-table": "^7.7.9",
    "@types/scrollmagic": "^2.0.2",
    "@types/styled-components": "^5.1.21",
    "@typescript-eslint/eslint-plugin": "^5.14.0",
    "@typescript-eslint/parser": "^5.14.0",
    "awesome-typescript-loader": "^5.2.1",
    "babel-loader": "^8.2.3",
    "eslint": "^8.10.0",
    "eslint-config-airbnb": "^19.0.4",
    "eslint-plugin-import": "^2.25.4",
    "eslint-plugin-jsx-a11y": "^6.5.1",
    "eslint-plugin-react": "^7.29.3",
    "eslint-plugin-react-hooks": "^4.3.0",
    "react-app-rewired": "^2.2.1"
  },
Run Code Online (Sandbox Code Playgroud)

CCC*_*CCC 5

最后通过降级eslint解决了。

 "devDependencies": {
    ...
    "eslint": "^7.32.0"
  }
Run Code Online (Sandbox Code Playgroud)


J W*_*uck 5

这似乎是升级到版本 8.0.0时可能出现的已知typescript-eslint 问题,该版本有一些重大更改。第一个链接上的一些评论表明通过降级到 eslint 版本 7.32.0 来解决。eslint

如果我理解正确的话,typescript-eslint v4不支持eslintv8,但typescript-eslint v5 支持。因此,您可以尝试将eslint降级到版本 7.32.0 或将typescript-eslint升级到 v5。