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

Gatsby项目运行ESLint出现ProjectNotFoundError问题求助

Gatsby项目中ESLint报ProjectNotFoundError的解决方法

问题现象

运行ESLint时抛出如下错误:

Oops! Something went wrong! :(

ESLint: 7.32.0

[ProjectNotFoundError: File '/home/path_to_project/somefile.ts' doesn't match any project] {
  name: 'ProjectNotFoundError',
  message: "File '/home/path_to_project/somefile.ts' doesn't match any project"
}

相关配置

.eslintrc 配置

{
  "extends": [
    "react-app",
    "plugin:jsx-a11y/recommended",
    "prettier",
    "plugin:tailwindcss/recommended"
    // "airbnb"
  ],
  "plugins": ["jsx-a11y"],
  "rules": {
    "no-restricted-imports": [
      "error",
      {
        "patterns": ["@/features/*/*"]
      }
    ],
    "tailwindcss/classnames-order": "error",
    "tailwindcss/no-custom-classname": "error"
  },
  "settings": {
    "tailwindcss": {
      "groupByResponsive": true
    }
  },
  "overrides": [
    {
      "files": ["*.ts", "*.tsx"],
      "processor": "@graphql-eslint/graphql",
      "parser": "@typescript-eslint/parser",
      "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended"
      ],
      "env": {
        "es6": true
      }
    },
    {
      "files": ["*.graphql"],
      "parser": "@graphql-eslint/eslint-plugin",
      "plugins": ["@graphql-eslint"],
      "rules": {
        "@graphql-eslint/no-anonymous-operations": "error",
        "@graphql-eslint/naming-convention": [
          "error",
          {
            "OperationDefinition": {
              "style": "PascalCase",
              "forbiddenPrefixes": ["Query", "Mutation", "Subscription", "Get"],
              "forbiddenSuffixes": ["Query", "Mutation", "Subscription"]
            }
          }
        ]
      }
    }
  ]
}

.eslintignore 配置

node_modules/
.cache/
public/
.idea/
yarn-error.log
.yarn/

问题定位

注释掉.eslintrc中针对.ts/.tsx文件的配置段可临时解决问题,但进一步排查确认:错误根源在于"processor": "@graphql-eslint/graphql"这一配置项,注释该配置即可恢复正常。

解决方案

修改.eslintrc中针对*.ts/*.tsx的overrides配置,移除或注释掉processor字段:

{
  "overrides": [
    {
      "files": ["*.ts", "*.tsx"],
      // 移除或注释此行即可解决问题
      // "processor": "@graphql-eslint/graphql",
      "parser": "@typescript-eslint/parser",
      "extends": [
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended"
      ],
      "env": {
        "es6": true
      }
    },
    // 其余配置项保持不变
  ]
}

补充说明

@graphql-eslint/graphql处理器的作用是提取文件中的GraphQL代码片段进行校验,但它仅适用于包含GraphQL代码的文件,而非所有TS/TSX文件。将其全局应用于所有TS/TSX文件时,ESLint会尝试为每个TS文件匹配GraphQL项目配置,最终导致找不到对应项目的错误。

如果需要校验TS/TSX文件中的GraphQL代码,建议仅在包含GraphQL片段的特定文件上启用该处理器,比如通过更精确的文件匹配规则(如*.graphql.tsx),或者结合ESLint的文件过滤逻辑针对性启用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 00:05:25