在 jsconfig.json 中找不到“import-resolver-typescript/lib”错误

Nis*_*ish 14 javascript frontend typescript visual-studio-code next.js

问题:

错误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"]
    }
}


Run Code Online (Sandbox Code Playgroud)

eslint.rc

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

Run Code Online (Sandbox Code Playgroud)

眼镜

  • vscode:版本1.57.1
  • 节点:14.17.1(LTS)
  • 下一个:11.0.1

注意:我添加了 eslint-import-resolver-typescript 模块,但仍然不起作用。

截屏:

SS

Sol*_*lly 11

如果您使用的是 vscode,请尝试TypeScript \xe2\x80\xba Validate在设置中禁用。这为我解决了这个问题!

\n

编辑:

\n

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

\n

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

\n

  • 我已经为这个问题苦苦挣扎了好几个星期,直到这个问题出现为止,我尝试过的解决方案都没有奏效。谢谢.... (2认同)
  • 在设置.json 中。在 vscode 中按 f1 并输入 settings.json 并在其中添加该行。这刚刚解决了我的问题,谢谢 Solly。 (2认同)