我在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 Problems窗格的屏幕截图:
关于可能的重复项的说明
有许多关于不同模块的类似问题,甚至一些关于import/extensions
的问题,但建议的解决方案都没有帮助。我都试过了。在输入这个问题时,我还尝试了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
是可行的,但随后ESLint抱怨Missing file extension for abc.ts
和Unable to resolve path to module abc
。我还多次重启了VSC和ESLint服务器。
发布于 2021-08-22 16:26:40
您错过了将此代码添加到eslint.json
文件中。
"plugins": ["import"],
参考:https://github.com/import-js/eslint-plugin-import#resolvers
https://stackoverflow.com/questions/68878189
复制相似问题