![](/img/trans.png)
[英]Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: jest.config.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.