【问题标题】:'import-resolver-typescript/lib' not found error in jsconfig.json在 jsconfig.json 中找不到“import-resolver-typescript/lib”错误
【发布时间】:2021-09-11 15:34:02
【问题描述】:

问题:

错误File '/Users/nish7/Documents/Code/WebDev/HOS/frontend/node_modules/eslint-import-resolver-typescript/lib' not found. The file is in the program because: Root file specified for compilation

繁殖步骤:

  • 创建下一个应用程序
  • npx jsconfig.json -t nextjs

jsconfig.json

    "compilerOptions": {
        "checkJs": false,
        "resolveJsonModule": true,
        "moduleResolution": "node",
        "target": "es2020",
        "module": "es2015",
        "baseUrl": ".",
        "paths": {
            "@/components/*": ["components/*"],
            "@/styles/*": ["styles/*"],
            "@/pages/*": ["pages/*"],
            "@/utils/*": ["utils/*"],
            "@/theme/*": ["theme/*"]
        }
    },
    "exclude": [
        "dist",
        "node_modules",
        "build",
        ".vscode",
        ".next",
        "coverage",
        ".npm",
        ".yarn"
    ],
    "typeAcquisition": {
        "enable": true,
        "include": ["react", "react-dom"]
    }
}


eslint.rc

{
  "extends": ["next", "next/core-web-vitals"]
}

规格

  • vscode:版本 1.57.1​​
  • 节点:14.17.1 (LTS)
  • nextjs: 11.0.1

注意:我添加了 eslint-import-resolver-typescript 模块,但仍然可以正常工作。

截图:

【问题讨论】:

  • 您后来解决了这个问题吗?我也遇到了同样的问题
  • 我试图修复它无法找到具体的解决方案,但是应用程序确实运行没有错误,所以我忽略了它。如果它真的困扰你,卸载 javascript/typescript IntelliSense 扩展可能会停止,但你也不会获得 IntelliSense 功能。
  • 也有同样的问题。我正在努力寻找一种方法来关闭错误消息。

标签: javascript typescript visual-studio-code frontend next.js


【解决方案1】:

只需重新启动所有 vscode 窗口,这在我的情况下有效。

【讨论】:

    【解决方案2】:

    如果您使用的是 vscode,请尝试在设置中禁用 TypeScript › Validate。这为我解决了!

    编辑:

    找到了比完全禁用验证更明智的方法;在 Vscode 设置中设置 TypeScript SDK

    "typescript.tsdk": "./node_modules/typescript/lib"

    【讨论】:

    • 我已经为这个问题苦苦挣扎了好几个星期,直到这个问题我才尝试过任何解决方案。谢谢....
    • 我们应该在哪里添加那个键?
    • 在 settings.json 中。在 vscode 中按 f1 并输入 settings.json 并在那里添加该行。这刚刚解决了我的问题,谢谢 Solly。
    【解决方案3】:

    也许你还没有为 typescript 安装 linter。 你可以使用 npm 全局安装它:

    npm i -g eslint-import-resolver-typescript
    

    【讨论】:

    • 这实际上为我解决了它
    猜你喜欢
    • 2020-11-30
    • 2021-12-24
    • 2020-12-26
    • 2020-03-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-16
    • 2021-05-16
    • 2012-04-10
    相关资源
    最近更新 更多