简体   繁体   English

解析错误:已为 @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

I've just used create-react-app to start a new typescript react app and then installed firebase. I ran firebase init , selected the typescript option, enabled es lint and enabled functions.我刚刚使用 create-react-app 启动了一个新的 typescript react 应用程序,然后安装了 firebase。我运行了firebase init ,选择了 typescript 选项,启用了 es lint 和启用的功能。

As soon as I uncommented the boilerplate function code in functions/index.ts, I noticed some warnings in VS Code...一旦我取消注释 functions/index.ts 中的样板 function 代码,我注意到 VS Code 中的一些警告......

functions/eslintrc.js:函数/eslintrc.js:

在此处输入图像描述

Giving error: "Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: .eslintrc.js. The file must be included in at least one of the projects provided"给出错误: “解析错误:已为@typescript-eslint/parser设置了“parserOptions.project”。该文件与您的项目配置不匹配:.eslintrc.js。该文件必须至少包含在提供的项目之一中“

functions/tsconfig.json:函数/tsconfig.json:

在此处输入图像描述

functions/src/index.ts:函数/src/index.ts:

在此处输入图像描述

giving error: "Parsing error: Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'.eslint"给出错误: “解析错误:‘--jsx’选项的参数必须是:‘preserve’、‘react-native’、‘react’.eslint”

functions/package.json:功能/包.json:

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    "build": "tsc",
    "serve": "npm run build && firebase emulators:start --only functions",
    "shell": "npm run build && firebase functions:shell",
    "start": "npm run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "engines": {
    "node": "14"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^9.8.0",
    "firebase-functions": "^3.14.1"
  },
  "devDependencies": {
    "@typescript-eslint/eslint-plugin": "^3.9.1",
    "@typescript-eslint/parser": "^3.8.0",
    "eslint": "^7.6.0",
    "eslint-config-google": "^0.14.0",
    "eslint-plugin-import": "^2.22.0",
    "firebase-functions-test": "^0.2.0",
    "typescript": "^3.8.0"
  },
  "private": true
}

I don't understand these errors.我不明白这些错误。 Can someone please help?有人可以帮忙吗?

Thanks谢谢

further to the above excellent suggestion by Evelyn Hathaway, and after I installed just the functions with no hosting and I changed the ".eslingrc.js: file除了 Evelyn Hathaway 提出的上述出色建议,在我只安装了没有托管的功能之后,我更改了“.eslingrc.js:文件

FROM

 .eslingrc.js
    parserOptions: {
    project: ["tsconfig.json",
   "tsconfig.dev.json"],

to

.eslingrc.js
   parserOptions: {
   project: ["./functions/tsconfig.json",
   "./functions/tsconfig.dev.json"],

At last the seemed to work after I spent a frustrating day.....在我度过了令人沮丧的一天之后,终于似乎工作了......

The first error from TypeScript ESLint is related to not being able to find a project tsconfig.json that matches your functions. TypeScript ESLint 的第一个错误与无法找到与您的功能匹配的项目tsconfig.json有关。

To fix this, we need to tell TypeScript ESLint where the other tsconfig.json is by editing your parserOptions .要解决此问题,我们需要通过编辑您的parserOptions来告诉 TypeScript ESLint 其他tsconfig.json在哪里。

.eslintrc.js

// [...]
"parser": "@typescript-eslint/parser",
"parserOptions": {
  "project": [
    "./tsconfig.json",
    "./functions/tsconfig.json",
  ]
}
// [...]

To fix the parsing issue related to JSX for your React files, you must add the jsx compiler option to your tsconfig.json configurations that include JSX.要修复与 React 文件的 JSX 相关的解析问题,必须将jsx编译器选项添加到包含 JSX 的tsconfig.json配置中。 This will likely be your non-function configuration, and you will most likely need to set it to react-jsx for React v17+ or react in all other cases for Create React App.这可能是您的非功能配置,您很可能需要将其设置为react-jsx以用于 React v17+ 或在所有其他情况下对 Create React App 进行react

tsconfig.json

{
  "compilerOptions": {
    "jsx": "react-jsx"
    // [...]
  }
  // [...]
}

暂无
暂无

声明:本站的技术帖子网页,遵循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 (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` 错误:无法加载在“.eslintrc.js”中声明的解析器“@babel/eslint-parser”:找不到模块“@babel/core/package.json” - Error: Failed to load parser '@babel/eslint-parser' declared in '.eslintrc.js': Cannot find module '@babel/core/package.json' 创建反应应用程序 - 没有打字稿,得到错误:无法加载解析器&#39;@typescript-eslint/parser&#39; - create react app - without typescript , got Error: Failed to load parser '@typescript-eslint/parser' 无法加载在 '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' React Native 中的“.eslintrc.js”是什么? - What is “.eslintrc.js” in React Native? 为什么 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 .eslintrc.js 用于 React 17 和 JSX,无需导入“react” - .eslintrc.js for React 17 and JSX without import 'react' 带有子文件夹的 typescript 项目中的 eslint 配置 - eslint configuration in a typescript project with subfolders
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM