Visual Studio Code中的TypeScript运行生成任务失败 [英] TypeScript Run Build Task in Visual Studio Code fails

查看:399
本文介绍了Visual Studio Code中的TypeScript运行生成任务失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Windows 10上的Visual Studio Code中使用运行构建任务"命令来使用Git Bash编译TypeScript,但出现此错误:

I am trying to use the "Run Build Task" command in Visual Studio Code on Windows 10 to compile TypeScript with Git Bash, but I get this error:

反斜杠似乎被解释为转义符,因此它们消失了.

It seems that the backslashes are being interpreted as escape characters, so they disappear.

当我将默认外壳程序切换为Powershell或cmd.exe时,不会发生此问题.另外,无论我是全局(npm i -g typescript)还是本地(npm i typescript)安装TypeScript,都将发生相同的问题.最后,我怀疑我的%PATH%环境变量可能也需要修复.

This issue does not happen when I switch the default shell to Powershell or cmd.exe. Also, the same issue happens no matter if I install TypeScript globally (npm i -g typescript) or locally (npm i typescript). Finally, I suspect that my %PATH% environment variable may need fixing as well.

这是我一直在使用的tsconfig.json文件:

This is the tsconfig.json file I have been using:

{
  "compileOnSave": true,
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "sourceMap": true
  }
}

我的最终目标是简单地在TypeScript代码文件上按Ctrl+S并将其立即转换为JavaScript(当然,如果TS文件有效).

My end goal is to simply press Ctrl+S on a TypeScript code file and have it immediately transpile to JavaScript (given the TS file is valid, of course.)

推荐答案

在GitHub上的vscode存储库中有一个关于此的未解决问题.查看链接

There is an open issue in the vscode repository on GitHub about this. See link

构建配置中的路径分隔符在运行构建命令之前被转义/删除了#35593

问题在于vscode假定Windows路径应在Windows系统上使用.但是git bash使用UNIX路径分隔符,这会导致问题.

The issue is that vscode assumes that Windows paths should be used on a Windows system. However git bash uses UNIX path seperators, which causes the issue.

GitHub上的用户 Atomfighter10101 建议:

The user Atomfighter10101 on GitHub suggests:

在构建任务中,将错误的"command"命令:/c/ProgramData/Anaconda3/python ${file}更改为正确的"command"命令: /c/ProgramData/Anaconda3/python \"${file}\".

In build task change the wrong command of "command": /c/ProgramData/Anaconda3/python ${file}, to the right command of "command": /c/ProgramData/Anaconda3/python \"${file}\".

(很明显,您的用例将python更改为tsc)

这篇关于Visual Studio Code中的TypeScript运行生成任务失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆