我用——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


当前回答

我今天遇到了这个问题,上面的解决方案都没有帮助。我遇到的问题是,在同一个目录中有两个文件,它们共享相同的文件名(无扩展名)。例如,src / foo。ts和src/Foo.tsx。重命名其中一个文件修复了linter错误。看到@typescript-eslint /解析器# 955。

其他回答

我使用一个符号链接从我的项目文件夹指向我的主文件夹:

/opt/project/workspace => ~/worspace .

使用符号链接路径~/workspace打开VSCode,错误始终存在。

使用原来的路径:/opt/project/workspace打开VSCode可以解决这个问题。

这应该不是问题,但现在确实是。

你可以为eslint配置创建一个单独的TypeScript配置文件(tsconfig.eslint.json)。该文件扩展了tsconfig配置和设置,包括必须检测的文件的key。

.eslint.js:

// ...
parserOptions: {
  // ...
  project: "./tsconfig.eslint.json",
  // ...
},
// ...

tsconfig.eslint.json:

{
  "extends": "./tsconfig.json",
  "include": [
    // ...
    "babel.config.js"
  ]
}

或者如果你想忽略它,你可以把它放在。eslintignore。

eslintignore:

// ...
babel.config.js

简单地通过在.eslintrc.js中添加ignorePatterns选项来指示eslint忽略它们:

module.exports = {
  root: true,
  parser: '@typescript-eslint/parser',
  parserOptions: {
    project: './tsconfig.json',
  },
  ignorePatterns: ["babel.config.js"],
  ...

由于检测您的项目配置文件没有多大价值,您可以安全地忽略它们。

另外,我不会让它们成为你的tsconfig的一部分。Json或创建一个特殊的tsconfig.eslint.json文件,仅用于检测目的。

对我来说,问题源于tsconfig中使用exclude属性忽略的一些文件,但eslint并没有忽略它们。

通常,如果有人想要TSC忽略文件,那么同样的方法也会应用到eslint中。所以只需复制粘贴.tsconfig配置中的exclude值到.eslintrc配置中的ignorePatterns属性。

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.