VS Code 是否安装 TypeScript,如果安装了:在哪里?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31189875/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Does VS Code install TypeScript, and if so: where?
提问by DeborahK
I recently read that installing VS Code also installs the TypeScript compiler. Is this true? If so, where is it installed?
我最近读到安装 VS Code 也会安装 TypeScript 编译器。这是真的?如果有,安装在哪里?
I found a tsc.js file here:
我在这里找到了一个 tsc.js 文件:
C:\Users\Deb\AppData\Local\Code\app-0.3.0\resources\app\server\lib\typeScript
But I am not finding a tsc.exe
anywhere.
但我找不到tsc.exe
任何地方。
回答by DeborahK
After some trial and error I came to the conclusion that VS Code does NOTinstall the TypeScript compiler.
一些试验和错误,我得出的结论是,VS代码确实不安装打字稿编译器。
The TypeScript compiler does have to be manually installed using npm install -g typescript
.
TypeScript 编译器确实必须使用npm install -g typescript
.
If installing under Windows on a machine that has had Visual Studio 2012/2013/2015 installed, the machine may also have other versions of TypeScript installed here: C:\Program Files (x86)\Microsoft SDKs\TypeScript\
如果在安装了 Visual Studio 2012/2013/2015 的机器上在 Windows 下安装,该机器也可能在此处安装了其他版本的 TypeScript:C:\Program Files (x86)\Microsoft SDKs\TypeScript\
If that is the case, VS Code maytry to use the version installed there. To prevent this, remove any references to the above TypeScript path from the environment path variable.
如果是这种情况,VS Code可能会尝试使用安装在那里的版本。为防止出现这种情况,请从环境路径变量中删除对上述 TypeScript 路径的任何引用。
To check the default version of the TypeScript compiler that will be found, use the command line and type: tsc -v
. This should give you the version number.
要检查将找到的 TypeScript 编译器的默认版本,请使用命令行并键入:tsc -v
。这应该给你版本号。
回答by vitaminjeff
I ran across this issue while attempting to build some TypeScript in Visual Studio Code while following along in @DeborahK's Pluralsight course "Angular with TypeScript".
我在尝试在 Visual Studio Code 中构建一些 TypeScript 时遇到了这个问题,同时在@DeborahK 的 Pluralsight 课程“Angular with TypeScript”中学习。
I came across the same error message in the Visual Studio Code OUTPUT panel.
我在 Visual Studio Code OUTPUT 面板中遇到了相同的错误消息。
'tsc' is not recognized as an internal or external command, operable program or batch file.
'tsc' 不是内部或外部命令,也不是可运行的程序或批处理文件。
I had recently done a global installation of TypeScript 1.8.9 from npm.
我最近从 npm 全局安装了 TypeScript 1.8.9。
npm install -g typescript
However, checking the TypeScript compiler version in my cmd shell would show an older version, 1.3.0.
但是,在我的 cmd shell 中检查 TypeScript 编译器版本会显示旧版本 1.3.0。
$ tsc -v
To get around this, I removed references from the "Path" variable in my "System variables" (Advanced system settings > Environment Variables... > System variables). I removed the following path:
为了解决这个问题,我从“系统变量”(高级系统设置 > 环境变量... > 系统变量)中的“路径”变量中删除了引用。我删除了以下路径:
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.1\
C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.1\
I learned that the Visual Studio 2013 installation I also had on the same machine included an installation of TypeScript 1.3.0. Cleaning my "Path" variable fixed the output on my TypeScript compiler version check.
我了解到我在同一台机器上的 Visual Studio 2013 安装也包括 TypeScript 1.3.0 的安装。清理我的“路径”变量修复了我的 TypeScript 编译器版本检查的输出。
Sadly, I still had the issue in Visual Studio Code. The thing that inevitably fixed it for me was a reboot.
遗憾的是,我在 Visual Studio Code 中仍然遇到了这个问题。不可避免地为我修复它的事情是重新启动。
If you got this far down in the thread, that's what fixed it for me. YMMV.
如果你在线程中走得这么远,那就是为我修复它的原因。天啊。
回答by Pierre Goch
Shell command 'tsc' still giving error about command not found, although I had run
Shell 命令 'tsc' 仍然给出有关未找到命令的错误,尽管我已经运行了
- npm install -g typescript (and tsc -v returns version 1.7.5)
- npm install -g typescript(和 tsc -v 返回版本 1.7.5)
In the end I used external command:
最后我使用了外部命令:
"command": "C:/Users/user1/AppData/Roaming/npm/tsc.cmd",
"isShellCommand": "false"
"command": "C:/Users/user1/AppData/Roaming/npm/tsc.cmd",
“isShellCommand”:“假”
And then it built
然后它建了
回答by natemcmaster
You found it. tsc.js is the entry point for the TypeScript compiler. There is no tsc.exe.
你找到了。tsc.js 是 TypeScript 编译器的入口点。没有 tsc.exe。
回答by ChristianB
To be clear: VS Code does not bring a TS Compiler. You currently have two Options:
需要明确的是:VS Code 没有带 TS 编译器。您目前有两个选项:
- VS 2013/2015 Plugin (brings tsc.exe) => You do not Need VStudio for this Plugin to run.
- Using NodeJS & installing TS Compiler via package Manager npm
- VS 2013/2015 插件(带 tsc.exe)=> 你不需要 VStudio 来运行这个插件。
- 使用 NodeJS 并通过包管理器 npm 安装 TS Compiler
I recommend to all VS Code users to install NodeJS. In fact, the main things needed for compiling are in tsc.js, which need to be run in a host (=by any JavaScript execution engine). This can be either tsc.exe or nodejs, however, there are differences. NodeJS allows watching a file (e.g. using libuv for detecting changes on saving a ts file to compile automatically). I recommend NodeJS as Long as you do not use VStudio. TSC.exe might(!) be faster because it runs on Chakra now, which is the new Edge-Engine. However, NodeJS uses Google v8 which should also be quite fast. I also experienced PATH-Problems with tsc.exe. VS Code really runs independent from the compiler, it is not merged with the Compiler as heavy as msbuild with vstudio. Therefore VSCode will fail if there is no PATH entry. I never had Problems with NodeJS.
我建议所有 VS Code 用户安装 NodeJS。实际上,编译所需的主要内容在 tsc.js 中,它需要在主机中运行(=通过任何 JavaScript 执行引擎)。这可以是 tsc.exe 或 nodejs,但是,存在差异。NodeJS 允许查看文件(例如,使用 libuv 检测保存 ts 文件以自动编译的更改)。我推荐 NodeJS,只要你不使用 VStudio。TSC.exe 可能(!)更快,因为它现在在 Chakra 上运行,这是新的 Edge-Engine。但是,NodeJS 使用 Google v8,这也应该很快。我还遇到了 tsc.exe 的 PATH 问题。VS Code 真正独立于编译器运行,它没有像 msbuild 和 vstudio 那样沉重的与编译器合并。因此,如果没有 PATH 条目,VSCode 将失败。我从来没有遇到过 NodeJS 的问题。
Best, Christian
最好的,基督徒