在VS代码中使用ESLint时,所有TypeScript文件都会出现以下两个错误:

Definition for rule 'import/extensions' was not found.eslint(import/extensions)
Definition for rule 'import/no-extraneous-dependencies' was not found.eslint(import/no-extraneous-dependencies)

VSC问题窗格中的屏幕截图:

enter image description here

关于可能重复的注释

对于不同的模块,甚至import/extensions个模块,都有许多类似的问题,但建议的解决方案都没有帮助.我都试过了.在输入这个问题时,我还try 了Stack Overflow建议的每个线程中发布的每个解决方案.

这是我的.eslintrc.json:

{
  "env": {
      "es2021": true,
      "node": true
  },
  "extends": [
      "airbnb-typescript/base",
      "plugin:@typescript-eslint/recommended"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
      "ecmaVersion": 12,
      "sourceType": "module",
      "project": "./tsconfig.json"
  },
  "plugins": [
      "@typescript-eslint"
  ],
  "rules": {
      "@typescript-eslint/no-use-before-define": "off"
  }
}

package.json:

{
  "name": "graph-userdata-gateway",
  "version": "1.0.0",
  "description": "Gateway for PowerApps Microsoft Graph API custom connector to query user data with application permissions.",
  "main": "src/index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git@gitlab.yobitti.fi:powerapps/graph-userdata-gateway.git"
  },
  "author": "Benjamin Pettinen / YO-bitti Oy",
  "license": "UNLICENSED",
  "dependencies": {
    "@microsoft/microsoft-graph-client": "^3.0.0",
    "dedent": "^0.7.0",
    "express": "^4.17.1",
    "isomorphic-fetch": "^3.0.0",
    "md5": "^2.3.0",
    "node-fetch": "^2.6.1"
  },
  "devDependencies": {
    "@types/dedent": "^0.7.0",
    "@types/express": "^4.17.13",
    "@types/isomorphic-fetch": "0.0.35",
    "@types/md5": "^2.3.1",
    "@types/node-fetch": "^2.5.12",
    "@typescript-eslint/eslint-plugin": "^4.29.2",
    "@typescript-eslint/parser": "^4.29.2",
    "eslint": "^7.32.0",
    "eslint-config-airbnb-base": "^14.2.1",
    "eslint-config-airbnb-typescript": "^13.0.0",
    "eslint-plugin-import": "^2.24.1",
    "typescript": "^4.3.5"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES6",
    "module": "CommonJS",
    "esModuleInterop": true,
    "noImplicitAny": true,
    "moduleResolution": "Node",
    "outDir": "dist",
    "sourceMap": true
  }
}

我试着删除整个node_mobules,重新运行npm install,并在.eslintrc.json中使用extends.如果我删除airbnb-typescript/base,错误就会消失,但我会从ESLint中丢失Airbnb样式.相反,使用airbnb-base是可行的,但埃斯林特抱怨大约Missing file extension for abc.tsUnable to resolve path to module abc.我还多次重启了VSC和ESLint服务器.

推荐答案

你错过了在你的eslint.json文件中添加这个.

"plugins": ["import"],

或者,

"extends": ["plugin:import/recommended"]

参考:https://github.com/import-js/eslint-plugin-import#resolvers

Typescript相关问答推荐

TypeScript将键传递给新对象错误

如何使类型只能有来自另一个类型的键,但键可以有一个新值,新键应该抛出一个错误

JS Redux Devtools扩展不工作

SortKey类型不起作用,尽管它使用的单个类型工作正常<>'

我们过go 不能从TypeScript中的联合中同时访问所有属性?

如何访问Content UI的DatePicker/中的sx props of year picker?'<>

具有动态键的泛型类型

如何将CSV/TXT文件导入到服务中?

React Typescript项目问题有Redux-Toolkit userSlice角色问题

是否可以针对联合类型验证类型属性名称?

在列表的指令中使用intersectionObservable隐藏按钮

声明文件中的类型继承

如何在使用条件类型时使用void

如何从对象或类动态生成类型

如何在不违反挂钩规则的情况下动态更改显示内容(带有状态)?

如何从接口中省略接口

使用强制转换编写打字函数的惯用方法

是否可以将类型参数约束为不具有属性?

确保财产存在

元组解释