Typescript -w(手表)不工作在我的安装
Typescript -w(watch) is not working in my installation
我已经安装了Typescript 2.0.6,我也有节点安装。如果我尝试用"-w"在监视模式下编译文件,则不工作。它抛出如下错误:
ts5001: the current host does not support the '--watch' option
使用下面的命令编译我的typescript文件"index.ts"
tsc -w index.ts
如果有人知道,请帮助我如何在监视模式下编译代码。
2021年的最新答案
有一个内置的--watch
/-w
选项,参见TS编译器选项(在列表的最后)。
或者一旦你设置了tsconfig.json
与outDir
和rootDir
:
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "ES2020", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "ES2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
"outDir": "src/main/resources/static/js", /* Redirect output structure to the directory. */
"rootDir": "src/main/resources/static/ts" /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
}
}
那么你可以调用
tsc --watch
第二个选项不是我个人尝试过的,但它是文件监视的另一个选项,请参阅配置监视以了解更多细节,但这里是他们的示例tsconfig.json
设置来自官方网站:
{ // Some typical compiler options "compilerOptions": { "target": "es2020", "moduleResolution": "node" // ... }, // NEW: Options for file/directory watching "watchOptions": { // Use native file system events for files and directories "watchFile": "useFsEvents", "watchDirectory": "useFsEvents", // Poll files for updates more frequently // when they're updated a lot. "fallbackPolling": "dynamicPriority" } }
您不能通过使用tsc
运行typescript代码来获得watch
功能
像这样运行node tsc.js -w index.ts
来源:https://github.com/Microsoft/TypeScript/issues/2375
我遇到了这个问题,对我来说,这是一个向我的环境变量/PATH添加正确路由的问题。打开"开发者命令提示符",输入"where tsc"。你应该得到四条不同的路由:
1) C:'Program Files (x86)'Microsoft sdk 'TypeScript'3.0'tsc.exe
2) C:'Program Files (x86)'Microsoft sdk 'TypeScript'3.0'tsc.js
3) C: '用户* yourUserName * ' AppData '漫游' npm ' tsc
4) C: '用户* yourUserName * ' AppData '漫游' npm ' tsc.cmd
我最初的想法是将第一个添加到我的PATH中,但是为了使用"tsc -w"而需要的那个实际上是第三个。
所以把这个添加到你的PATH: C:'Users*yourUserName*'AppData'Roaming'npm'
如果这是你的问题,你应该都准备好了。
这是我的工作:
- 通过运行
- 将运行
watch
脚本的npm
任务添加到tasks.json
(见下文) - 将
watch
脚本添加到packages.json
(见下文)
npm -i typescript
在本地安装typescript
要添加到tasks.json
的任务:
{
"type": "npm",
"script": "watch"
}
要添加到packages.json
的脚本
"watch": "node ./node_modules/typescript/bin/tsc -w"
- 我的shareService在angular 2中发送值工作正常,但当我渲染我的另一个组件时,会获得默认值
- 我的django模板布尔变量是't在javascript中按预期工作
- 为什么不是'我的JS滑块正在工作
- 为什么不是'我的函数在解析云代码中工作吗?当我在Angular和Express中测试时,它是有效的
- 为什么jquery悬停在jsfiddle中可以工作,而在我的html布局中却不能
- 为什么这个jQuery可以作为一个小提琴工作,但在我的网页上没有
- 为什么我的JavaScript在Safari上的严格模式下不能正常工作
- 由于某种原因,我的JavaScript函数无法工作
- 为什么获胜'我的自定义功能工作
- 我需要一个jQuery函数来只工作在700px以上的屏幕大小,无法在我的代码中发现错误
- 我的动画没有按预期工作
- 为什么不是't我的“;虚拟的“;阵列工作
- 为什么动态加载的事件在我的代码中不能正常工作
- 我的时间倒计时脚本在谷歌浏览器中工作正常,但在其他浏览器中打开时它显示为南楠
- 关于使用.className的建议,目前还没有;我不能在我的圈子里工作
- onbeforeunload事件在我的代码中没有触发,但其他示例可以工作
- 如何获得所需的自动对焦验证以在 html 表单上工作?- 我的尝试无法验证
- 为什么不工作我的函数xmlParser().请帮帮我
- 点击后不工作我的功能
- 不工作我的ajax调用函数myalert()