Getting an “Unknown provider: e” error with a production version of an AngularJS app

穿精又带淫゛_ 提交于 2019-12-23 06:06:20

问题


Why am I getting an "Unknown provider: e" error when hosting a production version of an Angular 7/AngularJS hybrid app in IIS?

I have an Angular 7/AngularJS hybrid app that I'm running. Everything runs fine in development mode using "npm start". However, after building a production version, the page gives me a

[$injector:unpr] Unknown provider: e

error. I've tried only running the Angular 7 code and that works fine. I've tried debugging and my angularjs code in an app.js file is being executed fine. The error seems to be coming from my app.module.ts when the code

this.upgrade.bootstrap(document.documentElement, ['app'], { strictDi: false })"

is executed.

export class AppModule {
  constructor(private upgrade: UpgradeModule) { }
  ngDoBootstrap() {
    this.upgrade.bootstrap(document.documentElement, ['app'], { strictDi: false });
  }
}
declare var angular: any;

angular
  .module("app")
  .directive("example", downgradeComponent({ component: ExampleComponent }) as angular.IDirectiveFactory);

Not sure why I only get this error in production mode. I've deployed the app as an application in IIS. Any help would be appreciated. Thanks.


回答1:


Use Strict Annotation Mode to Find Minification Bugs

angular.bootstrap(element, ['app'], { strictDi: false })

From the Docs:

  • strictDi - disable automatic function annotation for the application. This is meant to assist in finding bugs which break minified code. Defaults to false.

— AngularJS angular.bootstrap API Reference


How to Enable Strict Annotation Mode from HTML

<body ng-app="app" ng-strict-di="true">
   <!-- ... -->
</body>

From the Docs:

  • ngStrictDi (optional) boolean
    if this attribute is present on the app element, the injector will be created in "strict-di" mode. This means that the application will fail to invoke functions which do not use explicit function annotation (and are thus unsuitable for minification), as described in the Dependency Injection guide, and useful debugging info will assist in tracking down the root of these bugs.

— AngularJS ng-app Directive API Reference

For additional information, see

  • AngularJS Developer Guide - Using Strict Dependency Injection



回答2:


On your angular.json, look at your "production" object. There might be a buildOptimizer or aot setting that might be generating an issue with the transpiled .js. I believe that the code is expecting the minified variable ("e") but at the moment of execution, the code hasn't been minified.



来源:https://stackoverflow.com/questions/58867254/getting-an-unknown-provider-e-error-with-a-production-version-of-an-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!