TypeScript "Compile on save" feature not working in Visual Studio 2015

JavascriptVisual StudioCompilationTypescriptVisual Studio-2015

Javascript Problem Overview


The "Compile on save" feature isn't working for me after upgrading to Visual Studio 2015. When I make a change to a .ts file in my project and save, the status bar at the bottom of the IDE says Output(s) generated successfully, but the generated .js file doesn't change.

Here's what I've tried:

  • adding the following to the root <Project> element in my .csproj:

      <PropertyGroup>
          <TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
      </PropertyGroup>
    
  • checking and unchecking the "Automatically compile TypeScript files which are not part of a project" option in Tools -> Options -> TypeScript -> Project:

enter image description here

  • double checking to make sure "Compile on save" is checked in my project's TypeScript Build properties:

enter image description here

What am I missing?

As a side note, the TypeScript compilation step does work as expected when triggered by a regular build.

Javascript Solutions


Solution 1 - Javascript

For me it was this option in tsconfig.json:

"compileOnSave": true,
"compilerOptions": { ... },

Restart Visual Studio for this change to take effect.

Solution 2 - Javascript

I stumbled upon this problem today: I fixed that by using the new "watch":true compiler option, also available through JSON in most recent TypeScript versions:

{
  "compilerOptions": {
    "watch": true
  }
}

After doing that, I had to solve another issue related to the following error that appeared in the output window:

Object doesn't support property or method 'watchFile'

It turned out that my system was using an outdated version of TypeScript (1.0.x), despite I was sure I had a newer one that came with the Visual Studio 2015 Update 1 (1.7). If you run into this problem, you can easily check your tsc version by typing tsc -v from a command-prompt.

If it says 1.0.x or anything < 1.7, it's probably due to the fact that you have some old references in your PATH environment variable. Be sure you have 1.7 or later installed by checking inside your Microsoft SDKs folder, which is the one used by Visual Studio to install the TypeScript packages as they get updated:

C:\Program Files (x86)\Microsoft SDKs\TypeScript

If not, update accordingly. Open CPanel > System > Advanced > Environment Variables, select System Variables and click on Edit; browse through the list looking for any reference to the TypeScript folder, change one of them to make it point to your TypeScript most recent installed version (1.7 or above) and delete any other dupes. See also screenshot below:

enter image description here

For additional details, read this post on my blog.

Solution 3 - Javascript

Solution:

For me, and I am quite sure this is also the case for others, this was due to a mistake in the tsconfig.json.

You need to add "compileOnSave": true. But in the global section not inside compilerOptions.

Wrong:
{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "compileOnSave": true

  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

Correct:
{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5"

  },
"compileOnSave": true,
  "exclude": [
    "node_modules",
    "wwwroot"
  ]
}

Best regards,

Anders Both Basechat.

Solution 4 - Javascript

This issue seems to have been resolved with the most recent update to the TypeScript Language Services extension.

See this answer for instructions on how to apply this update.

Solution 5 - Javascript

With typescript 2 you have to delete "outDir": from your tsconfig. Fixed the bug for me in visual studio.

Solution 6 - Javascript

In my case, I had installed Visual Studio Community 2015 along side VS 2012. I had been using Web Essentials for typescript in 2012 which appeared to conflict with 2015.

Uninstalling Web Essentials in 2012 fixed the issue for me.

Solution 7 - Javascript

Not sure if this will help anyone.

I though I was having issues compiling, but it was compiling on save. I just didn't have my solution explorer toolbar toggled to show all files.

The file was there, just waiting impatiently to be added to the project.

enter image description here

Solution 8 - Javascript

In project properties -> "TypeScript Build", you can also simply just uncheck "Do not emit outputs if any errors are reported." Having it checked seems to deactivate transpiling on save, where there is an error or not.

Solution 9 - Javascript

The "compileOnSave": true, wasn't working for me. I finally figured out that Visual Studio doesn't honor the "compileOnSave": true, value if it is defined in another .json file that you're extending. It has to be in the root in order for it to work.

Solution 10 - Javascript

locate the file i.e. C:\file.ts in your terminal/cmd and type

tsc file.ts -w // watches for file changes and converts on save

Solution 11 - Javascript

Check if you have the TypeScript version installed which is configured in the project. Somehow I received no warning that I don't have TypeScript 3.7 installed, but the compile-on-save feature stopped working silently.

Once I installed TypeScript 3.7, it was working again.

Solution 12 - Javascript

Exact same problem here. I am using Visual Studio 2015 update 3 and TypeScript 2.9.2.0. In tools/options/projects and solutions/external web tools, I upgraded $(PATH) to the second position. With all these configurations, compileOnSave: true doesn't work for me. The workaround solution is open a command line, run ng build --watch on the side and let node take care of auto compilation

Solution 13 - Javascript

I had a similar but not the same issue in Visual Studio 2019

  • My project was set up to use TypeScript 2.9
  • I had TypeScript 3.8 installed, and the code did compile, but wouldn't compile on save

I installed the older version, TypeScript 2.9, restarted VS and then it burst into life

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNathan FriendView Question on Stackoverflow
Solution 1 - JavascriptMiłosz WierzbickiView Answer on Stackoverflow
Solution 2 - JavascriptDarksealView Answer on Stackoverflow
Solution 3 - JavascriptAnders BothView Answer on Stackoverflow
Solution 4 - JavascriptNathan FriendView Answer on Stackoverflow
Solution 5 - JavascriptYvanView Answer on Stackoverflow
Solution 6 - JavascriptChristopher ThomasView Answer on Stackoverflow
Solution 7 - JavascriptZombieCodeView Answer on Stackoverflow
Solution 8 - JavascriptDominic WilliamsView Answer on Stackoverflow
Solution 9 - JavascriptDarylView Answer on Stackoverflow
Solution 10 - JavascriptWasiFView Answer on Stackoverflow
Solution 11 - JavascriptcheesusView Answer on Stackoverflow
Solution 12 - JavascriptYue YinView Answer on Stackoverflow
Solution 13 - JavascripttonyView Answer on Stackoverflow