【发布时间】:2021-10-22 22:52:52
【问题描述】:
我在 VS Code 中使用 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 的问题,但建议的解决方案都没有帮助。我都试过了。在键入此问题时,我还尝试了 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 服务器。
【问题讨论】:
-
你能把你的repo发到这里吗,它有助于更正确地追踪/尝试问题?
标签: typescript visual-studio-code eslint eslintrc eslint-config-airbnb