我从 VSCode 0.10.6 更新到 0.10.8,并第一次尝试使用 Typescript。不幸的是,当我告诉 VSCode 构建时,我收到错误:
tsc 不被识别为内部或外部命令...
以下是相关详情:
- I created a fresh "HelloWorld" project according to VS Code instructions https://code.visualstudio.com/Docs/languages/typescript. This included:
- I ran
npm init
一个新的 package.json
- I ran
npm i --save-dev typescript
因为我想要本地安装,而不是全局安装。
- 我创建了一个 launch.json 来定义一个 node.js 项目。
- 我创建了tasks.json 文件,并为 tsc 指定了设置。
- 我制作了一个settings.json 文件,如图所示 https://stackoverflow.com/questions/34430205/after-recent-update-vs-code-transpiling-stopped-working-tsc-is-not-recognized-a。这没有帮助。
- 我确实安装了 Visual Studio 2015 Community,但没有安装任何类型的 Typescript 扩展。当我在开发人员命令提示符下键入“where tsc”时,它回复“无法找到”。我认为这是一件好事。
我已经重新启动了 VSCode(多次)。我缺少什么?还需要做什么?
Update
我尝试了@zlumer 提供的解决方案。它成功地使打字稿编译器运行,但随后导致出现数千个错误。为了解决这个问题,我还必须调整 tsconfig.json 以排除 node_modules 文件夹:
"exclude": [
"node_modules"
]
可能有一个原因Typescript
没有全局安装,所以安装一下
npm install -g typescript // installs typescript globally
如果你想转换.ts
文件到.js
,根据您的需要执行此操作
tsc path/file.ts // file.ts will be converted to file.js
tsc // all .ts files will be converted to .js files with in the directory
tsc --watch // converts all .ts files to .js, and watch changes in .ts files
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)