解析错误:无法读取文件'…/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,清除缓存,但都无济于事。我猜我需要改变一些路径,但我不太擅长改变配置文件,所以我不想不小心破坏整个项目。


当前回答

对于那些使用Angular和eslintrc的人。Json,添加2颗星到项目节点,如下所示:

"overrides": [
    {
        "files": ["*.ts"],
        "parserOptions": {
            "project": ["**/tsconfig.json"],
        },

其他回答

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

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

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

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

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

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

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

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

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

一个特定于vcode的方法,对我来说是在根项目目录中创建一个.vscode文件夹,并将以下属性添加到设置中。Json文件在里面:

{
  "eslint.workingDirectories": [
    "src"
  ]
}

src可以是eslint作用域内的任何目录。

我突然开始看到这个错误使用vscode。重新启动vscode解决了我的问题