问题描述
我从VSCode 0.10.6更新到0.10.8,并首次尝试使用Typescript.不幸的是,当我告诉VSCode构建时,出现错误:
I updated from VSCode 0.10.6 to 0.10.8, and tried using Typescript for the first time. Unfortunately I when I tell VSCode to build, I get the error:
以下是相关详细信息:
- 我根据VS Code指令创建了一个新的"HelloWorld"项目 .这包括:
- 我运行了
npm init
一个新的包.json - 我之所以运行
npm i --save-dev typescript
是因为我想要本地安装,而不是全局安装. - 我创建了launch.json来定义一个node.js项目.
- 我创建了task.json文件,并为tsc指定了设置.
- I created a fresh "HelloWorld" project according to VS Code instructions. This included:
- I ran
npm init
for a new package.json - I ran
npm i --save-dev typescript
because I want a local install, rather than a global install. - I created a launch.json to define a node.js project.
- I created the tasks.json file, with prescribed settings for tsc.
我已经重新启动了VSCode(几次).我想念什么?还必须做些什么?
I have restarted VSCode (several times). What am I missing? What more must be done?
我尝试了@zlumer提供的解决方案.它成功使Typescript编译器运行,但随后导致成千上万的错误出现.为了解决这个问题,我还必须调整tsconfig.json以排除node_modules文件夹:
I tried the solution offered by @zlumer. It succeeded in making the typescript compiler run, but then it caused thousands of errors to appear. To fix that, I also had to adjust my tsconfig.json to exclude the node_modules folder:
"exclude": [ "node_modules" ]
推荐答案
问题是,如果在本地安装
tsc
,则tsc
不在您的PATH
中.The problem is that
tsc
is not in yourPATH
if installed locally.您应该修改您的
.vscode/tasks.json
,以包含tsc
的完整路径.You should modify your
.vscode/tasks.json
to include full path totsc
.要更改的行可能等于
"command": "tsc"
.您应该将其更改为
"command": "node"
并将以下内容添加到您的参数中:"args": ["${workspaceRoot}\\node_modules\\typescript\\bin\\tsc"]
(在Windows上).You should change it to
"command": "node"
and add the following to your args:"args": ["${workspaceRoot}\\node_modules\\typescript\\bin\\tsc"]
(on Windows).这将指示VSCode执行以下操作:
This will instruct VSCode to:
- 运行NodeJS(应将其全局安装).
- 将本地Typescript安装作为运行脚本传递.
(这几乎是
tsc
可执行文件的作用)(that's pretty much what
tsc
executable does)您确定不想全局安装Typescript吗?它应该使事情变得更容易,尤其是在您刚开始使用它的时候.
Are you sure you don't want to install Typescript globally? It should make things easier, especially if you're just starting to use it.
这篇关于无法将tsc识别为内部或外部命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
- I ran
- 我运行了