'Resolve Error: typescript with invalid interface loaded as resolver ESLint
I'm having ESLint in my project and getting an error Resolve Error: typescript with invalid interface loaded as resolver : import-no-restricted-paths
when I add the rule import/no-restricted-paths
tsconfig.json
{
"include": [
"./src/**/*",
"./generated/**/*"
],
"compilerOptions": {
"resolveJsonModule": true,
"target": "es5",
"module": "esnext",
"moduleResolution": "node",
"lib": [
"dom",
"es6"
],
"downlevelIteration": true,
"jsx": "react",
"declaration": false,
"sourceMap": true,
"baseUrl": "src",
"outDir": "./dist/js",
"paths": {
"@generated/*": ["../generated/*"],
"api": ["lib/api"],
"api/*": ["lib/api/*"],
"asset/*": ["lib/asset/*"],
"base/*": ["lib/base/*"]
},
// Rules
"noImplicitAny": false,
"strictNullChecks": true,
"noImplicitThis": true,
"alwaysStrict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"forceConsistentCasingInFileNames": true,
"esModuleInterop": true,
"isolatedModules": true
}
}
.eslint.json
module.exports = {
env: {
browser: true
},
settings: {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {
paths: "./tsconfig.json",
alwaysTryTypes: true
}
},
},
parser: "@typescript-eslint/parser",
parserOptions: {
tsconfigRootDir: ".",
sourceType: "module",
project: "./tsconfig.json"
},
extends: [
"plugin:import/recommended",
"plugin:import/typescript"
],
plugins: [
"@typescript-eslint",
"import"
],
overrides: [
{
files: [
"src/_migration/**"
],
rules: {
"import/no-restricted-paths": [
"error",
{
basePath: "./src",
zones: [
{ target: "./_migration", from: "./", except: ['./_migration'] }
],
},
]
}
},
],
rules: {
"import/no-unresolved": "off",
"@typescript-eslint/typedef": [
"error",
{
parameter: true
}
]
}
};
Solution 1:[1]
This seemed to do the trick for me.
npm install -D eslint-import-resolver-typescript
I don't want to delete package-lock.json
because I know from experience that doing so causes problems for my current project.
Solution 2:[2]
For me, it was just enough to restart the eslint server. On Visual Studio Code, you can do it with cmd+p and start typing:
>eslint: restart eslint server
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Joel Sullivan |
Solution 2 | Jeremy Caney |