在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问题窗格中的屏幕截图:
关于可能重复的注释
对于不同的模块,甚至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.ts
和Unable to resolve path to module abc
.我还多次重启了VSC和ESLint服务器.