Roaders Roaders - 1 year ago 130
TypeScript Question

How do I make Visual Studio overwrite my JS file when doing a Typescript build

I have Visual Studio and am using it to build my typescript project. I have one build.ts file that links to all my other TS files and they are all compiled to one app.js file (with an associated map file).

The build apparently works fine but if the js file is already there it is not updated.
If I delete the js file and build it is created no problem, it is only a problem if the js file is already there.
The js file is NOT read only.

I have solved this by adding a call to tsc in my prebuild event command line - this works fine. This does not seem ideal though as I have to have my build configuration setup in 2 different places. When I moved to Typescript 1.5 I got all sorts of odd errors as VS was on 1.5 but my build command was on 1.4.

I can live with the workaround but it seems like a fairly major failing by VS that it doesn't actually update my compiled output.

Answer Source

Often times this will happen when there is a compile time error in Typescript and the following options are checked:

  1. Compile on save: This will cause the build to be marked as succeeded even when there are compile error in Typescript.
  2. Do not emit outputs if an error are reported: This along with the previous option will make it seem that the build succeeds but the js file is not updated.

enter image description here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download