未找到规则“@typescript-eslint/no-redeclare”的定义

art*_*ras 15 typescript create-react-app

在我所有的.ts.tsx文件,我有像下面的截图文件中的第一个字符这样的警告:

在此处输入图片说明

我正在使用标准的 CRA 设置。这是我的package.json

{
  "name": "my-project",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "firebase": "^8.0.1",
    "formik": "^2.2.3",
    "i18next": "^19.8.3",
    "i18next-browser-languagedetector": "^6.0.1",
    "i18next-xhr-backend": "^3.2.2",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-firebaseui": "^4.1.0",
    "react-i18next": "^11.7.3",
    "react-router-dom": "^5.2.0",
    "react-scripts": "^4.0.0",
    "react-select": "^3.1.0",
    "react-spinners": "^0.9.0",
    "react-syntax-highlighter": "^15.3.0",
    "react-transition-group": "^4.4.1",
    "styled-components": "^5.2.1",
    "yup": "^0.29.3"
  },
  "devDependencies": {
    "@cypress/webpack-preprocessor": "^5.4.10",
    "@types/firebase": "^3.2.1",
    "@types/jest": "^26.0.15",
    "@types/react": "^16.9.56",
    "@types/react-dom": "^16.9.9",
    "@types/react-router-dom": "^5.1.6",
    "@types/react-select": "^3.0.23",
    "@types/react-syntax-highlighter": "^13.5.0",
    "@types/styled-components": "^5.1.4",
    "@types/yup": "^0.29.9",
    "cypress": "^5.5.0",
    "eslint-plugin-cypress": "^2.11.2",
    "i18next-parser": "^3.3.0",
    "typescript": "^4.0.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "eject": "react-scripts eject",
    "cypress:open": "cypress open",
    "test": "react-scripts test --runInBand",
    "extract": "i18next --config i18next-parser.config.js"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}
Run Code Online (Sandbox Code Playgroud)

和我的 tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
    "types": ["cypress"],
    "noFallthroughCasesInSwitch": true
  },
  "include": [
    "src"
  ]
}
Run Code Online (Sandbox Code Playgroud)

知道我错过了什么吗?

eve*_*ght 43

当我看到同样的错误时,我最近更新了我对项目的依赖。简单地重新启动 Visual Code 似乎消除了错误。

  • 这有帮助,谢谢。`shift + command + p` 然后重新启动扩展主机对我有用。 (3认同)
  • 谢谢,这就是我的情况,重新启动 VS Code 就是解决方案 (2认同)

Fab*_*sco 4

我遇到过同样的问题。我修复此问题的方法是 (a) 更新解析器并 (b) 创建使用最新版本的文件 eslintrc.json。

"@typescript-eslint/eslint-plugin": "^4.7.0",
"@typescript-eslint/parser": "^4.7.0",
"eslint-config-airbnb-typescript": "^12.0.0",
"eslint-config-prettier": "^6.15.0",
Run Code Online (Sandbox Code Playgroud)

eslintrc.json 是这样的:

module.exports = {
  "env": {
      "es2020": true,
      "node": true
  },
  "extends": [
    "react-app",
    "airbnb",
    "eslint:recommended",
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
      "ecmaVersion": 11,
      "sourceType": "module"
  },
  "plugins": [
    "prettier",
    "@typescript-eslint"
  ],
  "rules": {
    "prettier/prettier": ["error"],
    "no-console": ["error"]
  }
};
Run Code Online (Sandbox Code Playgroud)