reactjs - 解析错误:“parserOptions.project”已为@typescript-eslint/parser 设置。该文件与您的项目配置不匹配:.eslintrc.js
问题描述
我刚刚使用 create-react-app 启动了一个新的 typescript react 应用程序,然后安装了 firebase。我跑了firebase init
,选择了打字稿选项,启用了 es lint 并启用了功能。
一旦我取消注释functions/index.ts 中的样板函数代码,我就注意到VS Code 中的一些警告......
函数/eslintrc.js:
给出错误:“解析错误:“parserOptions.project”已为 @typescript-eslint/parser 设置。该文件与您的项目配置不匹配:.eslintrc.js。该文件必须包含在至少一个提供的项目中"
函数/tsconfig.json:
函数/src/index.ts:
给出错误:“解析错误:'--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
与您的函数匹配的项目有关。
为了解决这个问题,我们需要tsconfig.json
通过编辑你的parserOptions
.
.eslintrc.js
// [...]
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": [
"./tsconfig.json",
"./functions/tsconfig.json",
]
}
// [...]
要为 React 文件修复与 JSX 相关的解析问题,您必须将jsx
编译器选项添加到tsconfig.json
包含 JSX 的配置中。这可能是您的非功能配置,您很可能需要将其设置react-jsx
为 React v17+ 或react
在所有其他情况下为 Create React App。
tsconfig.json
{
"compilerOptions": {
"jsx": "react-jsx"
// [...]
}
// [...]
}
推荐阅读
- pyspark - 优化 pyspark 中的 parquet 文件
- vb6 - 我的 Inno Setup 安装程序无法在所有机器上正确加载 vb6 程序
- javascript - 使用正则表达式编辑 react props.children 以匹配和替换
- java - 如何在Android中断开但不取消配对已配对的蓝牙耳机
- kubernetes - Kubernetes CPU 管理策略与 AKS 上的 Windows 节点
- python - 选择带有“-x”参数的 argparse 选项
- vue.js - 我在 Vuetify 方法中遇到了 if 语句问题
- reactjs - 在我对 api 的发布调用后对不需要的刷新做出反应
- bash - “export”命令行 - 在 bash_profile 中声明的环境变量在后续会话中可用吗?
- c# - 在我的方法中添加进度条 - wpf c#