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

其他回答

执行npm i -D @types/node 包括对*.config.js文件的typescript支持:

tsconfig.json:

{
  "include": [
    "**/*.config.js" // for *.config.js files
  ]
}

然后重新加载IDE!

Linux -我的项目目录/home/user/projects是到/usr/share/dev/projects的符号链接我删除了符号链接和一切工作现在。

我得到的错误是告诉我无法找到任何。tsx文件在“../../../..”/{应用名称/路径}”

我希望我的故障排除时间能帮助到某人:)

对我来说,这个问题发生在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": [""]
}

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

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

在本例中,我们有多个.eslintrc和多个tsconfig。Json在目录树中。(一个用于服务器,一个用于React客户端,一个用于。/client。)

这在CLI中工作得很好,但在VS Code的插件中就不行了。

修复方法是将./client/.eslintrc项目值设置为相对于根目录,而不是相对于.eslintrc文件。将“。/tsconfig. conf”改为“。/tsconfig. conf”。./client/tsconfig. Json“to”。json”,IDE检测工作如预期。