我用——template typescript创建了一个新的React Native项目
我删除了作为样板的一部分的模板目录。
然后我继续添加ESLint:
module.exports = {
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: ["airbnb-typescript-prettier"]
};
然而,当我打开babel.config.js时,我得到这个错误
解析错误:"parserOptions. "已经为@typescript-eslint/parser设置了Project "。
该文件与您的项目配置不匹配:/Users/Dan/site/babel.config.js。
该文件必须包含在至少一个提供的项目中。eslint
Despite assurances that typescript definitely, absolutely, never caches anything, I suspected this was a caching issue after, when getting annoyed at incessant typescript errors while debugging and developing a feature, I modified my tsconfig.json to exclude my src directory temporarily. Upon reverting the change, and restarting my typescript server running through WebpackDevServer, I had this error, and got rid of it by doing yarn cache clean to clear my yarn cache, as well as rm -rf node_modules to delete my node modules folder. Then I re installed my packages with yarn and when I ran my devserver again, typescript/tslint no longer showed this error.
对我来说,这个问题发生在parserOptions中列出的项目时。项目扩展了基本的tsconfig。Json,它排除了这个文件。
删除extends: './tsconfig. txt。来自parserOptions中列出的项目的json。项目或从基本配置中删除exclude可以修复该问题。但是这种解决方法并不实用,因为我们需要扩展基本配置。
重写属性exclude将非常有帮助。
tsconfig.spec.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"types": ["jest"]
},
"include": ["**/*.spec.ts"],
"exclude": [""]
}
这个错误来自VSCode扩展吗?
错误是否有一个相对路径,即使它在同一个文件夹(或子文件夹)中(如下面的错误消息所示)?
Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: ../../../../../home/<ommitted>/projects/floor-planner/app/src/App.vue.
The file must be included in at least one of the projects provided.
如果是,使用CLI时检查是否仍然存在。
你可以从你的项目根目录运行eslint ..
如果没有发现这些错误,则很可能是通过符号链接打开了项目。
截至2021年8月,Eslint扩展不支持Symlinks。
在项目目录中,运行pwd -P来获取绝对路径。
在我的例子中,这导致
~/projects/floor-planner/app: pwd -P
/media/projects/2021-Q3/floor-planner/app
通过此路径打开项目。
Eslint应该不再显示错误。