angularjsminifygoogle-closure-compilerdependency-resolver

AngularJS 'unknown provider' after minification (ng-strict-di being activated)


I first concatenate all my js files via grunt-contrib-concat grunt task. With this one everything worked fine (no minification).

I'm trying to switch to Google's Closure Compiler so I can minify it and add source maps, to start I'm using this options: --compilation_level WHITESPACE_ONLY and --formatting=pretty_print and I'm passing files in the same order as I did before with the grunt task so i should have a first output similar to what I've got before.

NOTE: Thanks to some sublime text magic and a diff checker, I have been able to check that both of my final generated files got all the same controllers/services in the EXACT SAME order.

All my controllers weren't using the annotation syntaxe (dependencies being declared as string before controller) so i used ng-annotate and this script to solve this problem.

Now all my files are ready for minification. To be sure about that I even declared ng-strict-di on my app and temporarly switch back to the previous concatenation system. It works perfect and fails if I deliberatly put a typo in my controllers name.

So from this I thought Closure Compiler should have worked like a charm... But no, I'm facing an Unknown Provider error when angular try to inject my first service inside my app.run() function. (The .config() is executed well as I've no custom dependencies here as well as the three first dependencies of the .run(). It really is MY personnaly implemented dependencie that fail.)

Did someone already face a similar issue ? Any idea what could cause this ?


Solution

  • Ok... I found out that closure compiler do not import files the same way as the grunt task I used to use.

    When using the notation src/js/controllers/**/*.js I excpected it to import the files directly inside my controller folder but it didn't.

    I was sure to have checked this but I certainly made a mistake and compare the old file with the old file instead of the new one; that's why I thought I got all my dependencies in the file and in same order when checking...