簡體   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

我剛剛使用 create-react-app 啟動了一個新的 typescript react 應用程序,然后安裝了 firebase。我運行了firebase init ,選擇了 typescript 選項,啟用了 es lint 和啟用的功能。

一旦我取消注釋 functions/index.ts 中的樣板 function 代碼,我注意到 VS Code 中的一些警告......

函數/eslintrc.js:

在此處輸入圖像描述

給出錯誤: “解析錯誤:已為@typescript-eslint/parser設置了“parserOptions.project”。該文件與您的項目配置不匹配:.eslintrc.js。該文件必須至少包含在提供的項目之一中“

函數/tsconfig.json:

在此處輸入圖像描述

函數/src/index.ts:

在此處輸入圖像描述

給出錯誤: “解析錯誤:‘--jsx’選項的參數必須是:‘preserve’、‘react-native’、‘react’.eslint”

功能/包.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
}

我不明白這些錯誤。 有人可以幫忙嗎?

謝謝

除了 Evelyn Hathaway 提出的上述出色建議,在我只安裝了沒有托管的功能之后,我更改了“.eslingrc.js:文件

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

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

在我度過了令人沮喪的一天之后,終於似乎工作了......

TypeScript ESLint 的第一個錯誤與無法找到與您的功能匹配的項目tsconfig.json有關。

要解決此問題,我們需要通過編輯您的parserOptions來告訴 TypeScript ESLint 其他tsconfig.json在哪里。

.eslintrc.js

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

要修復與 React 文件的 JSX 相關的解析問題,必須將jsx編譯器選項添加到包含 JSX 的tsconfig.json配置中。 這可能是您的非功能配置,您很可能需要將其設置為react-jsx以用於 React v17+ 或在所有其他情況下對 Create React App 進行react

tsconfig.json

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM