I am trying to write a nodejs command line app with Typescript and I have the following tsconfig file:
{
"compilerOptions": {
"module": "commonjs",
"outDir": "dist"
},
"include": ["src/*.ts"]
}
When I use tsc
everything works as expected (*.js files appear in the dist folder).
However, when I run tsc -w
, the js files are created in the dist folder at first, but not updated when I change any of the ts files. Tsc seems to be seeing and compiling changes just fine, but fails to write the actual js files.
4:23:04 PM - File change detected. Starting incremental compilation...
4:23:04 PM - Compilation complete. Watching for file changes.
When I omit the outDir parameter from the tsconfig everything works (js files are being updated when chaning ts files). This is not a desired solution since I want js output to be in dist folder instead of src.
It also works correctly when I skip using the tsconfig.json file and run it directly:
tsc -w --outDir dist src/app.ts
Am I doing something wrong?
Running on win10, tsc 2.6.2, node 7.9.0
The tsconfig.json file specifies the root files and the compiler options required to compile the project. JavaScript projects can use a jsconfig.json file instead, which acts almost the same but has some JavaScript-related compiler flags enabled by default.
The tsconfig. json is generally put in the root folder of the project.
The include and exclude properties take a list of glob-like file patterns. The supported glob wildcards are: * matches zero or more characters (excluding directory separators)
I think I have this figured out.
Typescript 2.6 came with new --watch implementation. When downgrading to 2.5.3 everything works fine.
So this seems to be an issue with the new --watch thingy that manifests under specific conditions (win10, using outDir in tsconfig).
Reported it as a bug in Typescript issue tracker - https://github.com/Microsoft/TypeScript/issues/20739
For me this was fixed by disabling the option 'Use "safe write" (save changes to a temporary file first)' in WebStorm:
When enabled, the IDE deletes and renames files, which seems to confuse tsc --watch
.
(To see what it's doing, use tsc --extendedDiagnostics --listEmittedFiles
. Extended logs in Arnelism's GitHub issue.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With