我已经安装了Typescript 2.0.6,我也在安装节点。如果我尝试使用" -w"在监视模式下编译文件它不起作用。它抛出以下错误。
ts5001: the current host does not support the '--watch' option
使用以下命令编译我的打字稿文件" index.ts"
tsc -w index.ts
如果有任何需要,请帮助我如何在监视模式下编译代码。
答案 0 :(得分:1)
使用watch
tsc
功能
运行它
node tsc.js -w index.ts
答案 1 :(得分:0)
我遇到了这个问题,对我来说,这是向我的环境变量/ PATH添加正确的路由的问题。打开“开发人员命令提示符”,然后输入“ where tsc”。您应该获得四种不同的路线:
1)C:\ Program Files(x86)\ Microsoft SDKs \ TypeScript \ 3.0 \ tsc.exe
2)C:\ Program Files(x86)\ Microsoft SDKs \ TypeScript \ 3.0 \ tsc.js
3)C:\ Users *您的用户名* \ AppData \ Roaming \ npm \ tsc
4)C:\ Users *您的用户名* \ AppData \ Roaming \ npm \ tsc.cmd
我最初的想法是将第一个添加到我的PATH中,但是使用“ tsc -w”所需的实际上是第三个。
因此将其添加到您的PATH:C:\ Users *您的用户名* \ AppData \ Roaming \ npm \
如果这是您的问题,那么您应该准备就绪。
答案 2 :(得分:0)
这是为我工作的解决方法:
npm -i typescript
npm
脚本的watch
任务添加到tasks.json
(请参见下文)watch
脚本添加到packages.json
(见下文) 要添加到tasks.json
的任务:
{
"type": "npm",
"script": "watch"
}
要添加到packages.json
的脚本
"watch": "node ./node_modules/typescript/bin/tsc -w"
答案 3 :(得分:0)
只是这个问题的更新答案
或者一旦您使用 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
{ // 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"
}
}