0

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.

Norbert Norbertson
  • 2,102
  • 1
  • 16
  • 28
  • I believe this is something to do with the ordering of the code that is bundled into bundle.js. When I build the project in VS the order of files in tsconfig.json is honored. However, when I run the project and edit + save a .ts file with the "compileonSave" option set to true the order of the code bundled changes to some other order which breaks it. – Norbert Norbertson Aug 18 '17 at 14:08
  • If I can find the time I'll try a different bundling method. – Norbert Norbertson Aug 18 '17 at 14:09

1 Answers1

0

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.

Update:

No I was mistaken. It's not fixed. If I build the project then it fails to run because it does not honor the files compile order. However, when I edit the bundle directly and change the order and then further edit .ts files then bundle.js is rebuilt correctly. But if I close the project again and build it's incorrect. tsc still works on the command line to bundle in the correct order. This is all terribly buggy.

Update 2

As a work around I converted app.js back to JS and moved it out of the ts bundle. This is now loaded first before bundle.js and everything works fine.

Norbert Norbertson
  • 2,102
  • 1
  • 16
  • 28