简体   繁体   English

解析错误:“parserOptions.project”已为 @typescript-eslint/parser 设置为 gatsby/typescript

[英]Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser for gatsby/typescript

I've read a lot of posts with this same error message but all of them are regarding their.eslintrc or babel config file.我已经阅读了很多带有相同错误消息的帖子,但所有帖子都与他们的 .eslintrc 或 babel 配置文件有关。 I'm using the gatsby/typescript starter kit from their website here: https://www.gatsbyjs.com/starters/jpedroschmitz/gatsby-starter-ts我在这里使用他们网站上的 gatsby/typescript 入门工具包: https://www.gatsbyjs.com/starters/jpedroschmitz/gatsby-starter-ts

The problem is, when I create a server/index.ts file from the root, since its outside the src folder, on the first line of the file, I get: Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.问题是,当我从根目录创建一个 server/index.ts 文件时,由于它在 src 文件夹之外,在文件的第一行,我得到:解析错误:“parserOptions.project”已为 @typescript 设置-eslint/解析器。 The file does not match your project config: server/index.ts.该文件与您的项目配置不匹配:server/index.ts。 The file must be included in at least one of the projects provided.该文件必须至少包含在所提供的项目之一中。 I have the exact same set up as in the the starter kit and i tried including the server folder in tsconfig but with no luck.我的设置与入门工具包中的设置完全相同,我尝试在 tsconfig 中包含服务器文件夹,但没有成功。

tsconfig.json:
{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"],
      "@/static/*": ["./static/*"]
    }
  },
  "exclude": ["node_modules"],
  "include": ["./src/**/*", "./__helpers__/*"]
}

.eslintrc
{
  "env": {
    "browser": true,
    "es6": true,
    "node": true,
    "jest": true
  },
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 2019,
    "sourceType": "module"
  },
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "plugins": ["react", "react-hooks", "jsx-a11y", "prettier", "jest"],
  "extends": [
    "plugin:react/recommended",
    "airbnb",
    "prettier",
    "plugin:jest/recommended",
    "plugin:jest/style"
  ],
  "rules": {
    "jest/prefer-strict-equal": "error",
    "jest/prefer-to-have-length": "warn",
    "prettier/prettier": "error",
    "import/prefer-default-export": "off",
    "react/prop-types": "off",
    "react/jsx-filename-extension": "off",
    "react/jsx-props-no-spreading": "off",
    "import/no-extraneous-dependencies": [
      "error",
      {
        "devDependencies": [
          "**/*.test.[jt]s",
          "**/*.spec.[jt]s",
          "**/*.test.[jt]sx",
          "**/*.spec.[jt]sx"
        ]
      }
    ],
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "ts": "never",
        "tsx": "never",
        "js": "never",
        "jsx": "never"
      }
    ],
    "react/function-component-definition": [
      2,
      {
        "namedComponents": "function-declaration"
      }
    ]
  },
  "overrides": [
    {
      "files": "**/*.+(ts|tsx)",
      "parser": "@typescript-eslint/parser",
      "parserOptions": {
        "project": "./tsconfig.json"
      },
      "plugins": ["@typescript-eslint/eslint-plugin"],
      "extends": [
        "plugin:@typescript-eslint/eslint-recommended",
        "plugin:@typescript-eslint/recommended",
        "prettier"
      ],
      "rules": {
        "@typescript-eslint/explicit-function-return-type": "off",
        "@typescript-eslint/no-explicit-any": "off",
        "@typescript-eslint/no-var-requires": "off",
        "no-use-before-define": [0],
        "@typescript-eslint/no-use-before-define": [1],
        "import/no-unresolved": 0,
        "import/no-extraneous-dependencies": [
          "error",
          {
            "devDependencies": [
              "**/*.test.ts",
              "**/*.spec.ts",
              "**/*.test.tsx",
              "**/*.spec.tsx"
            ]
          }
        ],
        "quotes": "off",
        "@typescript-eslint/quotes": [
          2,
          "backtick",
          {
            "avoidEscape": true
          }
        ],
        "@typescript-eslint/no-unused-vars": [2, { "argsIgnorePattern": "^_" }]
      }
    }
  ],
  "settings": {
    "import/resolver": {
      "typescript": {
        "project": "."
      }
    },
    "react": {
      "version": "detect"
    }
  }
}

server/index.ts:
import express, { Express, Request, Response } from 'express';
import cors from 'cors';

const app: Express = express();
const port = 3000;

app.use(cors());
app.use(express.json());

app.get('/', (req: Request, res: Response) => res.send('Hello World!'));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));

In your tsconfig.json file you need to add your server folder to include :在您的 tsconfig.json 文件中,您需要添加服务器文件夹以include

"include": ["./src/**/*", "./__helpers__/*", "server/**/*" ]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解析错误:“parserOptions.project”已为@typescript-eslint/parser 设置。 该文件与您的项目配置不匹配:jest.config.js - Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: jest.config.js 解析错误:已为 @typescript-eslint/parser 设置“parserOptions.project”。 该文件与您的项目配置不匹配:.eslintrc.js - Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: .eslintrc.js (ESLint/赛普拉斯): 解析错误: ESLint 被配置为在 ` 上运行<tsconfigrootdir> /component/TestComponent.cy.ts` 使用 `parserOptions.project`</tsconfigrootdir> - (ESLint/Cypress): Parsing error: ESLint was configured to run on `<tsconfigRootDir>/component/TestComponent.cy.ts` using `parserOptions.project` 创建反应应用程序 - 没有打字稿,得到错误:无法加载解析器&#39;@typescript-eslint/parser&#39; - create react app - without typescript , got Error: Failed to load parser '@typescript-eslint/parser' eslint - 无法加载插件“@typescript-eslint” - eslint - Failed to load plugin '@typescript-eslint' 为什么 eslint 考虑 JSX 或一些反应 @types undefined,因为将 typescript-eslint/parser 升级到版本 4.0.0 - Why eslint consider JSX or some react @types undefined, since upgrade typescript-eslint/parser to version 4.0.0 npm 错误。 notarget 找不到与@typescript-eslint/parser@5.4.0 匹配的版本 - npm ERR! notarget No matching version found for @typescript-eslint/parser@5.4.0 找不到@typescript-eslint/no-unused-expressions&#39; - @typescript-eslint/no-unused-expressions' was not found 如何禁用@typescript-eslint/semi? - how disable @typescript-eslint/semi? 无法加载在 'package.json » eslint-config-react-app#overrides[0]' 中声明的解析器 '@typescript-eslint/parser':找不到模块 'typescript' - Failed to load parser '@typescript-eslint/parser' declared in 'package.json » eslint-config-react-app#overrides[0]': Cannot find module 'typescript'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM