首页 > 解决方案 > 如何解决:“找不到规则'@typescript-eslint/consistent-type-assertions'的定义”

问题描述

我的 React 应用程序没有因为错误而无法编译:未找到规则“@typescript-eslint/consistent-type-assertions”的定义

我有点不知所措。我无法在项目中找到任何当前规则定义。该项目最初正在编译。在我重组应用程序后开始出现错误。

该应用程序无法编译并出现错误:未找到规则“@typescript-eslint/consistent-type-assertions”的定义

包.json -

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@types/react-dom": "16.9.0",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.1.1",
    "styled-components": "^4.3.2",
    "typescript": "^3.5.3"
  },
  "scripts": {
    "start": "PORT=3005 react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --transformIgnorePatterns",
    "e2e": "./node_modules/.bin/cypress open"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@testing-library/dom": "^6.1.0",
    "@testing-library/jest-dom": "^4.0.1",
    "@testing-library/react": "^9.1.3",
    "@types/jest": "^24.0.18",
    "@types/lodash": "^4.14.137",
    "@types/node": "^12.7.2",
    "@types/react": "^16.9.2",
    "@types/react-router-dom": "^4.3.4",
    "@types/styled-components": "^4.1.18",
    "babel-jest": "^24.9.0",
    "cypress": "^3.4.1"
  }
}

标签: reactjstypescriptnpmcreate-react-apptypescript-typings

解决方案


刚刚更新react-scripts。我通过卸载并再次安装解决了它。在命令行中:

卸载:

npm uninstall react-scripts --save

并再次安装:

npm i react-scripts

推荐阅读