简体   繁体   English

解决错误:带有无效接口的打字稿加载为解析器 ESLint

[英]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我的项目中有 ESLint 并收到错误Resolve Error: typescript with invalid interface loaded as resolver : import-no-restricted-paths当我添加规则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 .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
            }
        ]
    }
};

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.我不想删除package-lock.json因为我从经验中知道这样做package-lock.json我当前的项目带来问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解决错误:webpack 在 Expo 升级到 SDK 45 后加载了无效接口作为解析器 - Resolve error: webpack with invalid interface loaded as resolver after Expo upgrade to SDK 45 解决 class 字段的“@typescript-eslint/no-invalid-this”问题,而不与“@typescript-eslint/no-this-alias”冲突 - Resolve “@typescript-eslint/no-invalid-this” issue for class fields without conflicting with “@typescript-eslint/no-this-alias” 为什么我收到错误无法解析模块路径? Eslint 与 Typescript - Why I got error Unable to resolve path to module? Eslint with Typescript 使用 eslint 从 graphql 解析器返回什么严格的 typescript 类型? - What strict typescript type to return from graphql resolver using eslint? 使用 babel 模块解析器和 typescript 时的 ESLint 问题 - ESLint issue when using babel module-resolver and typescript 在 monorepo 中设置 eslint-import-resolver-typescript - Setting up eslint-import-resolver-typescript in monorepo 将 eslint 与打字稿一起使用 - 无法解析模块的路径 - Using eslint with typescript - Unable to resolve path to module eslint / typescript:无法解析模块路径 - eslint / typescript: Unable to resolve path to module TypeScript eslint:防止接口相同命名的规则 - TypeScript eslint: Rule to prevent same naming of interface 为 typescript 接口标识符关闭 eslint camelCase - Turn off eslint camelCase for typescript interface identifiers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM