gpt4 book ai didi

reactjs - 解析错误 : "parserOptions.project" has been set for @typescript-eslint/parser. 该文件与您的项目配置不匹配 : . eslintrc.js

转载 作者:行者123 更新时间:2023-12-02 02:09:45 25 4
gpt4 key购买 nike

我刚刚使用 create-react-app 启动了一个新的 Typescript React 应用程序,然后安装了 firebase。我运行了 firebase init,选择了 typescript 选项,启用了 es lint 并启用了功能。

当我取消注释functions/index.ts中的样板函数代码时,我注意到VS Code中出现了一些警告...

函数/eslintrc.js:

enter image description here

给出错误:“解析错误:已为@typescript-eslint/parser设置“parserOptions.project”。该文件与您的项目配置不匹配:.eslintrc.js。该文件必须至少包含在所提供的项目之一中”

函数/tsconfig.json:

enter image description here

函数/src/index.ts:

enter image description here

给出错误:“解析错误:'--jsx'选项的参数必须是:'preserve','react-native','react'.eslint”

函数/package.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
}

我不明白这些错误。有人可以帮忙吗?

谢谢

最佳答案

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 compiler option到包含 JSX 的 tsconfig.json 配置。这可能是您的非功能配置,您很可能需要将其设置为 React v17+ 的 react-jsx 或 Create React App 的所有其他情况下的 react .

tsconfig.json

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

关于reactjs - 解析错误 : "parserOptions.project" has been set for @typescript-eslint/parser. 该文件与您的项目配置不匹配 : . eslintrc.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67876864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com