Norbert Norbertson Norbert Norbertson - 1 month ago 21
AngularJS Question

typescript compile on save breaks AngularJS in Visual Studio 2017

I have a Visual Studio Community 2017 (15.2) project with AngularJS 1.6.5 and a NancyFX server.

Code here:

https://github.com/GusBeare/NancyAngularTests

This is a playground for me to learn and test features I'd like to use on a real project.

All the AngularJS stuff is in Typescript files and my tsconfig.json tells the compiler to compile it all into a single JS file

Content/js/bundle.js
.

When I build and run the project everything works as expected and there are no issues. However, if I edit a .ts file while the app is running it breaks with this error:

angular.min.js:7 Uncaught Error: [$injector:nomod]
http://errors.angularjs.org/1.6.5/$injector/nomod?p0=mySPA


The compile on save seems to work fine since the
Content/js/bundle.js
is rebuilt on save. But why do I get the Angular error only on compile on save?

Am I doing something wrong in my AngularJS code or is this a Typescript/Visual Studio thing?

If I build and publish the project it runs fine under IIS and I can't break it.

Answer Source

I noticed that outside of VS if I compiled the typescript using tsc then the order of files in my tsconfig.json was honored so I assumed a bug in the VS typescript tools.

So I went to https://www.microsoft.com/en-us/download/details.aspx?id=48593 and noticed a new version had just been released (2.4.1).

Installing this fixed the issue for me. The ts compiler now reads the files in the specified order and bundles them correctly.