解析错误:无法读取文件'…/tsconfig.json'.eslint显示在src文件夹中的所有.ts文件中,包括index.ts。

我不知道如何设置配置。问题只显示一条红线,并使文件变为红色。但是,一切都能正常编译和运行。整个Node项目是使用firebase CLI创建的。

tsconfig。json文件:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

.eslintrc.js文件:

module.exports = {
  env: {
    browser: true,
    es6: true,
    node: true,
  },
  extends: [
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
  ],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: "tsconfig.json",
    sourceType: "module",
  },
  plugins: [
    "@typescript-eslint",
    "import",
  ],
  rules: {
    "@typescript-eslint/adjacent-overload-signatures": "error",
    "@typescript-eslint/no-empty-function": "error",
    "@typescript-eslint/no-empty-interface": "warn",
    "@typescript-eslint/no-floating-promises": "error",
    "@typescript-eslint/no-namespace": "error",
    "@typescript-eslint/no-unnecessary-type-assertion": "error",
    "@typescript-eslint/prefer-for-of": "warn",
    "@typescript-eslint/triple-slash-reference": "error",
    "@typescript-eslint/unified-signatures": "warn",
    "comma-dangle": "warn",
    "constructor-super": "error",
    eqeqeq: ["warn", "always"],
    "import/no-deprecated": "warn",
    "import/no-extraneous-dependencies": "error",
    "import/no-unassigned-import": "warn",
    "no-cond-assign": "error",
    "no-duplicate-case": "error",
    "no-duplicate-imports": "error",
    "no-empty": [
      "error",
      {
        allowEmptyCatch: true,
      },
    ],
    "no-invalid-this": "error",
    "no-new-wrappers": "error",
    "no-param-reassign": "error",
    "no-redeclare": "error",
    "no-sequences": "error",
    "no-shadow": [
      "error",
      {
        hoist: "all",
      },
    ],
    "no-throw-literal": "error",
    "no-unsafe-finally": "error",
    "no-unused-labels": "error",
    "no-var": "warn",
    "no-void": "error",
    "prefer-const": "warn",
  },
  settings: {
    jsdoc: {
      tagNamePreference: {
        returns: "return",
      },
    },
  },
};

我尝试重新启动VScode,清除缓存,但都无济于事。我猜我需要改变一些路径,但我不太擅长改变配置文件,所以我不想不小心破坏整个项目。


当前回答

当我在Windows 10上通过WSL 2进行typescript项目时,我在Visual Studio Code中得到了这个错误。

通过在VS Code中安装Remote - WSL扩展修复了这个问题。

文件托管在我的\wsl$\Ubuntu\home<user>\ location。错误消息指定了正确的文件位置,VS Code可以打开该文件。

上面使用根目录和解析器选项的修复没有帮助。

其他回答

如果你在IntelliJ的多模块项目中得到以下错误消息(例如,包含多个后端服务和前端模块的文件夹),IntelliJ可能无法告诉你该做什么。

在我的情况下,我得到了以下错误的顶部。ts文件:

为了解决这个问题,我点击了“ESLint设置…”,并选择了“手动ESLint配置”。

然后我在“Working directories:”中输入了前端模块根文件夹的路径,并在“eslint包”中选择了正确的eslint路径(在我的情况下,是在< fronttend -module-root>/node_modules/eslint)。

通过这种方式,我仍然可以让eslint工作,而不需要改变任何与项目相关的配置(它已经从CLI中的前端模块根文件夹中工作)。

我通过添加@typescript-eslint/parser来解决这个问题:

另一种方法是,如果您碰巧在项目的上面一层打开了Workspace文件夹(就像我的情况一样),只需用ACTUAL项目文件夹启动一个新的Workspace。这解决了我的Eslint错误。

解析错误:无法读取文件“d:\test\testproject\tsconfig.app.eslint.json” 我在这里遇到的一个主要问题是项目文件夹在vs code中打开的方式。

假设文件夹结构为 D:\test\testproject这里的“testproject”是你正在使用的angular项目。

如果你在vs code中打开测试文件夹,然后导航到testproject,如下所示

D:\test>
D:\test>cd testproject
D:\test\testproject> 

这样做将创建2个设置。Json文件,一个用于主打开的文件夹,一个用于子文件夹,这反过来又不允许正确应用设置。

所以总是在vscode中直接打开项目文件夹将有助于克服这个问题,当所有的依赖关系都在eslintrc中正确提及时。Json和tsconfig。Json文件将有助于解决这个问题。

更新你的eslintrc。Json文件,包含以下行:

“项目”:“PROJECT_NAME / tsconfig.json”

使用PROJECT_NAME作为项目的名称(不是宏)。