首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >找不到规则‘ESLint /extensions’的导入定义

找不到规则‘ESLint /extensions’的导入定义
EN

Stack Overflow用户
提问于 2021-08-22 03:06:47
回答 1查看 10.4K关注 0票数 24

我在VS代码中使用ESLint在所有TypeScript文件上得到以下两个错误:

代码语言:javascript
运行
复制
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 Problems窗格的屏幕截图:

关于可能的重复项的说明

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

这是我的.eslintrc.json

代码语言:javascript
运行
复制
{
  "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

代码语言:javascript
运行
复制
{
  "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

代码语言:javascript
运行
复制
{
  "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是可行的,但随后ESLint抱怨Missing file extension for abc.tsUnable to resolve path to module abc。我还多次重启了VSC和ESLint服务器。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-22 16:26:40

您错过了将此代码添加到eslint.json文件中。

代码语言:javascript
运行
复制
"plugins": ["import"],

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

票数 51
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68878189

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档