admin管理员组

文章数量:1410712

I have installed the Typescript 2.0.6, i am also having the node installation. If i try to pile a file in watch mode with "-w" it is not working. It throws the below error.

ts5001: the current host does not support the '--watch' option

Used the below mand to pile my typescript file "index.ts"

tsc -w index.ts

If any know please help me how to pile the code in watch mode.

I have installed the Typescript 2.0.6, i am also having the node installation. If i try to pile a file in watch mode with "-w" it is not working. It throws the below error.

ts5001: the current host does not support the '--watch' option

Used the below mand to pile my typescript file "index.ts"

tsc -w index.ts

If any know please help me how to pile the code in watch mode.

Share asked Nov 17, 2016 at 9:13 krrr25krrr25 6793 gold badges14 silver badges29 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 1

Updated answer for 2021

There is a built in --watch / -w option see the TS piler options (at the very end of the list).

Or once you have tsconfig.json setup with the outDir and rootDir:

{
  "pilerOptions": {
    /* Visit https://aka.ms/tsconfig.json to read more about this file */

    /* Basic Options */
    // "incremental": true,  /* Enable incremental pilation */
    "target": "ES2020",     /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
    "module": "ES2020",   /* Specify module code generation: 'none', 'monjs', '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. */
  }
}

Then you can just call

tsc --watch

This second option isn't one I've tried yet personally, but it's another option for file watching see Configuring Watch for more details, but here is their example tsconfig.json setup given from official site:

{   // Some typical piler options   
  "pilerOptions": {
    "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"   
  } 
}

You cannot get watch functionality by running typescript code by using tsc

Run it like node tsc.js -w index.ts

Source: https://github./Microsoft/TypeScript/issues/2375

I ran into this problem and, for me, it was a matter of adding the correct route to my environment variables/PATH. Open up the "Developer Command Prompt" and type in "where tsc". You should get four different routes:

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*yourUserName*\AppData\Roaming\npm\tsc

4) C:\Users*yourUserName*\AppData\Roaming\npm\tsc.cmd

My initial thought was to add the first one to my PATH, however the one you'll need in order to use "tsc -w" is actually the third one.

So add this to your PATH: C:\Users*yourUserName*\AppData\Roaming\npm\

If this was your issue, you should be all set.

This is the work around works for me:

  • install typescript locally by running npm -i typescript
  • Add npm task which runs the watch script to tasks.json (see below)
  • Add the watch script to packages.json (see below)

The task to be added to tasks.json:

{ "type": "npm", "script": "watch" } The script to be added to packages.json

"watch": "node ./node_modules/typescript/bin/tsc -w"

本文标签: javascriptTypescript w(watch) is not working in my installationStack Overflow