首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解析错误:"parserOptions.project“已为@typescript-eslint/解析器设置为gatsby/typescript

解析错误:"parserOptions.project“已为@typescript-eslint/解析器设置为gatsby/typescript
EN

Stack Overflow用户
提问于 2022-04-30 05:33:27
回答 1查看 1.3K关注 0票数 1

我读过很多带有同样错误信息的帖子,但它们都是关于它们的.eslintrc或babel配置文件的。我正在使用gatsby/typescript初学者工具包,来自他们的网站:https://www.gatsbyjs.com/starters/jpedroschmitz/gatsby-starter-ts

问题是,当我从根创建一个服务器/index.ts文件时,因为它在src文件夹之外,在文件的第一行,我得到:解析错误:"parserOptions.project“已经设置为@typescript eslint/解析器。该文件与您的项目配置不匹配: server/index.ts。该文件必须包含在所提供的至少一个项目中。我的设置与初学者工具包完全相同,我尝试将服务器文件夹包括在tsconfig中,但没有成功。

代码语言:javascript
复制
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}!`));
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-04-30 20:13:44

在tsconfig.json文件中,需要将服务器文件夹添加到include

代码语言:javascript
复制
"include": ["./src/**/*", "./__helpers__/*", "server/**/*" ]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72065978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档