You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

package.json中eslint-config-react-app配置无效,overrides属性类型错误

错误原因

ESLint的overrides配置项规范要求必须是数组格式,每个数组元素对应一套针对特定文件的覆盖规则,你当前的配置直接写了单个对象,不符合类型要求所以校验失败。

修正方法

找到项目package.json里的eslintConfig字段,把里面的overrides属性对应的值,改成包裹了原有对象的数组即可。

错误配置示例(package.json片段)

{
  "eslintConfig": {
    "extends": "react-app",
    "overrides": {
      "files": ["**/*.ts","**/*.tsx"],
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
        "ecmaVersion": 2018,
        "sourceType": "module",
        "ecmaFeatures": {"jsx":true},
        "warnOnUnsupportedTypeScriptVersion": true
      },
      "plugins": ["@typescript-eslint"],
      "rules": {
        "default-case":"off",
        "no-dupe-class-members":"off",
        "@typescript-eslint/no-angle-bracket-type-assertion":"warn",
        "no-array-constructor":"off",
        "@typescript-eslint/no-array-constructor":"warn",
        "@typescript-eslint/no-namespace":"error",
        "no-unused-vars":"off",
        "@typescript-eslint/no-unused-vars":["warn",{"args":"none","ignoreRestSiblings":true}],
        "no-useless-constructor":"off",
        "@typescript-eslint/no-useless-constructor":"warn"
      }
    }
  }
}

修正后的正确配置

{
  "eslintConfig": {
    "extends": "react-app",
    "overrides": [
      {
        "files": ["**/*.ts","**/*.tsx"],
        "parser": "@typescript-eslint/parser",
        "parserOptions": {
          "ecmaVersion": 2018,
          "sourceType": "module",
          "ecmaFeatures": {"jsx":true},
          "warnOnUnsupportedTypeScriptVersion": true
        },
        "plugins": ["@typescript-eslint"],
        "rules": {
          "default-case":"off",
          "no-dupe-class-members":"off",
          "@typescript-eslint/no-angle-bracket-type-assertion":"warn",
          "no-array-constructor":"off",
          "@typescript-eslint/no-array-constructor":"warn",
          "@typescript-eslint/no-namespace":"error",
          "no-unused-vars":"off",
          "@typescript-eslint/no-unused-vars":["warn",{"args":"none","ignoreRestSiblings":true}],
          "no-useless-constructor":"off",
          "@typescript-eslint/no-useless-constructor":"warn"
        }
      }
    ]
  }
}

修改完成后重启ESLint服务即可生效,如果仍有报错可以删除node_modules文件夹和包管理锁文件(package-lock.json/yarn.lock/pnpm-lock.yaml)后重新安装依赖。

内容的提问来源于stack exchange,提问作者CodeWithMe

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 02:27:03