thardy / generator-ngbp

Yeoman generator based on the ngBoilerplate kickstarter, a best-practice boilerplate for any scale Angular project built on a highly modular, folder-by-feature structure.
100 stars 23 forks source link

issue compiling sample app #1

Closed DallanQ closed 10 years ago

DallanQ commented 10 years ago

When I compile the sample app (which I haven't changed after the initial generation) and run it using a python SimpleHTTPServer, I get the following error:

Uncaught Error: [$injector:modulerr] Failed to instantiate module due to: Error [$injector:modulerr] Failed to instantiate module due to: Error [$injector:unpr] Unknown provider: a

If I remove the uglify step from the compile, everything works great.

Any ideas?

I really like this generator! Thank-you for creating it!

thardy commented 10 years ago

I am able to reproduce after running "grunt compile". It definitely has something to do with the minification, which is supposed to be handled by ngMin.

Running ngMin before uglify should not cause this problem. ngMin isn't doing what it's supposed to do, or else there's a bug in the implementation.

I'll have to debug this when I get time. Thanks for letting me know. In the meantime, you can get around the issue by manually naming the dependencies via...

myApp.controller('myCtrl', ['$scope', '$http', function($scope, $http) { }])

DallanQ commented 10 years ago

Thanks!

thardy commented 10 years ago

I've determined this is due to generator-ngbp being too "clever" with it's js code. ngmin only detects code it can alter via an "angular.module("blah", []).controller...". The fact that I'm using "app.controller..." is preventing ngmin from doing its thing.

There are two choices as I see it. One, we can just use declarative naming of dependencies. Two, we can see if we can help fix ngmin to be a tad smarter, maybe fork and use a convention of "app." or "module." to help trigger it's work.

I've submitted an issue with ngmin to see if it's worth the effort.

DallanQ commented 10 years ago

Thank-you for looking into this. I've enjoyed working with your generator so far. I hope it catches on.

thardy commented 10 years ago

Ok, I've removed the usage of ngmin until I can figure out how to get it to work with enclosures. Please don't hold your breath. Someone else is welcome to look into it.

Going back to old school array declarations of dependencies. Just look at any of the controller declarations for an example, or just look at my comment above. It's not just for controllers, of course, any Angular declaration that accepts a dependency needs to use this syntax (service, factory, etc).

DallanQ commented 10 years ago

It also works if I remove the enclosures and use the usual

angular.module('foo.bar', []) .configure(function(..) {...}) .controller('MyController', function(...) {...});

is there a reason not to go this route? That is, do other parts of the generator rely upon the enclosures?

thardy commented 10 years ago

It's certainly an option. It comes down to whether enclosures or not having to do the declarative syntax is more valuable. I'm curious what other people think. I could be persuaded.

thardy commented 10 years ago

Check out the latest version, 0.1.1, if you haven't yet. I added ng-annotate support, and it works great, even with enclosures.

DallanQ commented 10 years ago

Thanks! I'll check it out.