src文件夹中的所有.ts个文件(包括index.ts个)中都显示了错误Parsing error: Cannot read file '.../tsconfig.json'.eslint.

我不知道如何设置配置.问题只是显示一条红线,并使文件变为红色.不过,一切都可以正常运行.整个 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",
      },
    },
  },
};

我曾try 重新启动VScode,清除缓存,但都无济于事.我猜我需要更改一些路径,但我不太擅长更改配置文件,所以我不想意外 destruct 整个项目.

推荐答案

默认情况下,相对于当前工作目录解析project(在parserOptions中).如果在包含tsconfig.json的文件夹的不同工作目录中运行eslint,@typescript eslint/parser将无法找到该文件.

要解决这个问题,可以将tsconfigRootDir设置为__dirname,这将使解析器解析相对于.eslintrc.js的项目配置:

module.exports = {
  // ...
  parserOptions: {
    project: "tsconfig.json",
    tsconfigRootDir: __dirname,
    sourceType: "module",
  },
  // ...
}

如果你遇到麻烦

/path/to/.eslintrc.js
  0:0  error  Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: .eslintrc.js.
The file must be included in at least one of the projects provided

this question.

Node.js相关问答推荐

如何使用updateMany()和Node.js的方法?

查询嵌套数组中的最后一个元素具有特定值的mongoDB集合中的文档

运行JEST测试时找不到模块&q;错误

express返回意外的URL

如何使用聚合管道交换键值对

如何在Mongoose for MongoDB中编写此查询

类扩展值[object object]不是构造函数或null

Playwright - 无法在 img 标签中使用 file:// 访问本地文件

Rails 7导入npm yaml包时出现404错误

BrowserRouter 无法渲染组件

是Electron 的密码和登录凭据的安全存储吗?

在数组的另一个对象中获取数组的mongoose 对象

MERN 堆栈项目中的 React [create-react-app] 正在提供依赖项

如何在 mongoDB 中用值 0 填充缺失的文档?

Mongodb v4.0 Transaction, MongoError: Transaction numbers are allowed on a replica set member or mongos

在 express 中添加故意延迟

Puppeteer 记录在 page.evaluate

当我try 向我的 S3 存储桶 (Node.js) 发送内容时,AWS 缺少凭证

在 Node.js 中写入 CSV

用于轻松部署和更新的 Node.js 设置