No module found during bootstrap, unable to init ocLazyLoad
I am always getting the following exception. How to resolve this?
Note: I am using requirejs.
No module found during bootstrap, unable to init ocLazyLoad.
You should always use the ng-app directive or angular.boostrap when you use ocLazyLoad.
I always get it as well. As far as I can tell, everything works just fine.
I'm going to do a PR to make it configurable to turn this message off in the config stage, perhaps as
$ocLazyLoadProvider.config({
suppressBootstrapWarning: true
});
The offending code says:
if (modulesToLoad.length === 0 && !((window.jasmine || window.mocha) && angular.isDefined(angular.mock))) {
console.error('No module found during bootstrap, unable to init ocLazyLoad. You should always use the ng-app directive or angular.boostrap when you use ocLazyLoad.');
}
Oddly enough, my bootstrap code looks like:
angular.element(document).ready(function() {
angular.bootstrap(document, [app['name'], function() {
angular.element(document).find('html').addClass('ng-app');
}]);
});
I think the test is in there as a guide for people who may have misconfigured something, but there are valid reasons to fail the test even when you've got things working just as you need. It seems in our case not to like that (a) we put ng-app on after bootstrapping (this pleases mocha, when we're in unit test mode), and (b) we inject the $ocLazyLoad _provider_ very early.
It seems a workaround until it's fixed would be to set angular.mock = true or something and hope some other library isn't also using truthy for that property as a proxy for "is in test mode", or that $ocLazyLoad doesn't change its behavior otherwise in "test mode". :)
Yes, you'll get this error if oclazyload cannot find ng-app. It's not recommended because the lib might want to reload angular native modules if one of your lazy loaded dependencies requires it (angular-animate, angular-cookies, ...), since it won't know that it has been loaded.
It may not be a problem if you call angular.bootstrap yourself, not sure about that though, I'd have to make some tests :)
When is the "right" time to inject the provider or service to allow it to recognize ng-app, then? My project is private, so I can't just point right to it, unfortunately...
You can see I pushed a commit to my fork.... you're welcome to it if you want it. I won't both with an actual pull request because I'm still not convinced the error is spurious. :)
Having noted that the entire "find the ng-app" section has a comment that says, "this might not be necessary" or something to that effect, I was doubly confused about what's going on... my plan had been to use ocLazyLoad only via regular injection, not as a directive or any other fancier parts of the system, which is a reason why I suspected that in my use case, the error message wasn't applicable.
Ya, I am bootstrapping my angular bu above way, But Exactly, I am not getting the solution for. What I will change in my code, so I will get a solution.
For those who are still using angularjs in 2021, and came across this issue - you can silence this warning with the following hack:
Object.defineProperty(angular.element.prototype, 'className', {
get() {
return this[0] === document ? 'ng:app:ng' : undefined;
}
});