【问题标题】:Resolve Error: typescript with invalid interface loaded as resolver ESLint解决错误:作为解析器 ESLint 加载的带有无效接口的打字稿
【发布时间】:2021-11-25 11:34:08
【问题描述】:

我的项目中有 ESLint,当我添加规则 import/no-restricted-paths 时出现错误 Resolve Error: typescript with invalid interface loaded as resolver : 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
            }
        ]
    }
};

【问题讨论】:

  • 我通过删除 lockfile 和 node_modules 并重新安装所有内容来解决此问题。
  • 重启 vscode 对我有帮助????

标签: typescript eslint typescript-eslint


【解决方案1】:

这似乎对我有用。

npm install -D eslint-import-resolver-typescript

我不想删除package-lock.json,因为我从经验中知道这样做会给我当前的项目带来问题。

【讨论】:

    猜你喜欢
    • 2022-07-27
    • 1970-01-01
    • 2017-12-05
    • 2019-08-07
    • 2022-06-23
    • 2020-05-24
    • 2018-12-03
    • 2019-12-12
    相关资源
    最近更新 更多