jon*_*ode 39 typescript eslint typescript-eslint
Resolve Error: typescript with invalid interface loaded as resolver : import-no-restricted-paths
我的项目中有 ESLint,当我添加规则时出现错误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
}
}
Run Code Online (Sandbox Code Playgroud)
.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
}
]
}
};
Run Code Online (Sandbox Code Playgroud)
Joe*_*van 74
这似乎对我有用。
npm install -D eslint-import-resolver-typescript
Run Code Online (Sandbox Code Playgroud)
我不想删除,package-lock.json
因为我从经验中知道这样做会给我当前的项目带来问题。
小智 24
对我来说,重新启动 eslint 服务器就足够了。在 Visual Studio Code 上,您可以使用cmd+p并开始输入:
>eslint: restart eslint server
Run Code Online (Sandbox Code Playgroud)
小智 6
添加这个来.eslintrc
为我解决这个问题。
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
31452 次 |
最近记录: |