VSCode jsconfig.json 给出 ts 错误指定用于编译的根文件

问题描述 投票:0回答:4

我已经在 stackoverflow 上寻找答案了jsconfig.json 给出了 ts 错误。 我试过:

  1. 设置
"exclude": ["node_modules"]

在 jsconfig.json 中

  1. 设置
"noEmit": true 

在 jsconfig.json 的“compilerOptions”中

  1. 删除node_moduls和package-lock.json并在npm安装后

npm install --save @types/dotenv

没有任何帮助:(

我只使用 js 文件或 jsx。我的操作系统 ubuntu (Focal Fossa)。有人向我解释错误是从哪里来的吗?它与 TypeScript 有什么关系?如何彻底摆脱它?除了上面已经做的事情我还能做什么?

完整的错误消息是:

{
    "resource": "path/jsconfig.json",
    "owner": "typescript",
    "severity": 8,
    "message": "File 'path/node_modules/agent-base/dist/src/index' not found.\n  The file is in the program because:\n    Root file specified for compilation",
    "source": "ts",
    "startLineNumber": 1,
    "startColumn": 1,
    "endLineNumber": 1,
    "endColumn": 2
}
visual-studio-code
4个回答
10
投票

您可以在 Visual Studio 中使用以下方法作为解决方法。 文件 > 首选项 > 设置,在搜索栏中输入“typescript validate”,然后取消选中结果。


4
投票

我实际上也遇到了类似的问题,我通过更改 VS Code 中的 TypeScript 版本设法解决了这个问题。只需打开任意 JavaScript 文件,然后单击右下角的“选择语言模式”按钮即可。它应该允许您选择工作区 TS 版本而不是全局版本。


0
投票

从您的

.json
文件中删除任何评论。注释,即
// my comment
不是有效的 JSON。


0
投票

下午好。我删除了项目的文件夹并使用 tsc --init 错误消失了,我使用的是 Windows 11。也就是说,在一个空文件夹中,由于某种原因,它起作用了..

© www.soinside.com 2019 - 2024. All rights reserved.