Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minification Breaking Application #8

Closed
anthify opened this issue Mar 9, 2016 · 10 comments
Closed

Minification Breaking Application #8

anthify opened this issue Mar 9, 2016 · 10 comments

Comments

@anthify
Copy link

anthify commented Mar 9, 2016

Since adding ngMeta it runs as you would expect it to but when minified it breaks throwing the following error.

Uncaught Error: [$injector:unpr] Unknown provider: eProvider <- e

I'm struggling to locate the cause. Some help would be appreciated.

Thanks!

@anthify
Copy link
Author

anthify commented Mar 9, 2016

Finally fixed this.

.run(['ngMeta', function(ngMeta) { ngMeta.init(); }]);

Perhaps add this in the readme for anyone using it with minification?

@vinaygopinath
Copy link
Owner

Minification messes with implicit dependency injection.

If you're not using a build tool like ng-annotate (in your Grunt/Gulp/whatever-the-cool-kids-are-using-these-days process), you must explicitly handle dependency injection before minification for config, run and all components of AngularJS - controller, filter, service, factory etc.

I will add a note in the readme about this, thanks.

@anthify
Copy link
Author

anthify commented Mar 10, 2016

Cool, I wasn't aware of ng-annotate.

Thanks for the advice and getting back to me.

I'll close this now, cheers.

@anthify anthify closed this as completed Mar 10, 2016
@prov-alexandra
Copy link

prov-alexandra commented May 3, 2016

Hey, just checking on this -- I didn't see anything in the readme and initializing ngMeta in our run block didn't solve the issue. We still get the following exception when we use minification, even with atostudios' run block suggestion:
Unknown provider: eProvider <- e <- ngMeta <- ngMeta

Is ng-annotate the only work around? If so it would be really helpful to list that as a requirement for anyone hoping to use ng-meta with minification.

@vinaygopinath
Copy link
Owner

ng-annotate is not a dependency of this module. It's just a helper that adds explicit dependency injection exactly as in @atostudios's run block code.

If this error seems to show up only while running minified code, I guess there's a function that has implicit dependencies. This is not an issue with ngMeta, but rather with all minified Angular code.

For full minification support, please replace

angular.config(function(ngMetaProvider, stateProvider) {
...
})

With

angular.config(['ngMetaProvider', 'stateProvider', function(ngMetaProvider, stateProvider) {
...
}])

You might need to do this for controllers as well. The dependency injection Angular doc has more information.

The run block in the README uses the minification-friendly code, but I will add a section for minification. Thanks.

@prov-alexandra
Copy link

We actually do use explicit dependency injection everywhere in our application, in order to make it safe for minification. So, our run block starts with:
.run(['$window', '$rootScope', 'ngMeta', function ($window, $rootScope, ngMeta) { ngMeta.init()

and we still see the error eProvider <- e <- ngMeta <- ngMeta only when we minify our js. So maybe this is a different issue than @atostudios?

Thanks

@vinaygopinath
Copy link
Owner

I'd be able to help you better if you could show me the line that's throwing this error.
Please check if all uses of ngMeta are injected explicitly and that there's no mismatch (like ngMetaProvider being injected in place of ngMeta, or vice versa).

@prov-alexandra
Copy link

.run(['$window', '$rootScope', 'ngMeta', function ($window, $rootScope, ngMeta) is the line that's throwing the error -- I can remove all other references to ngMeta and I will still see that error.

I'll try to do some more investigation though -- maybe the way we're importing the package is incorrect or something.

@rsnazell
Copy link

Hi @prov-alexandra - how did you resolve this issue? I am getting the same error. I'm using @ngInject to handle dependency injection. It breaks following minification with error: eProvider <- e <- ngMeta <- ngMeta

Any help would be much appreciated :-)

@christiaanwesterbeek
Copy link

christiaanwesterbeek commented Sep 19, 2017

Seems still an issue today. I minify and uglify with webpack using npm run build:prod:

rimraf dist && cross-env NODE_ENV=production && webpack -p

Running my application renders this error at startup:

Uncaught Error: [$injector:unpr] Unknown provider: eProvider <- e <- ngMeta <- ngMeta

Uncompressed my app works fine and ngMeta is working properly. This is the only occurrence of ngMeta in my source code:

.run((ngMeta) => {
  'ngInject'
  ngMeta.init()
})

Changing that to the following has no effect and the error still occurs.

.run(['ngMeta', (ngMeta) => {
  ngMeta.init()
}])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants