Aot and minification failing in Angular 4 with external modules

不问归期 提交于 2019-12-10 09:34:36

问题


I am using Angular CLI to build an Angular 4 app. Before deployment to prod, I would like to do aot and minification. So I executed the following command

ng build --environment=prod --prod --base-href /myapp/

This gives me the below error

ERROR in Error encountered resolving symbol values statically. Calling function 'ControlValueAccessorProviderFactory', function calls are not supported. Consi
der replacing the function or lambda with a reference to an exported function, resolving symbol DatePicker in D:/myapp/node_modules/angular-i
o-datepicker/src/datepicker/datePicker.d.ts, resolving symbol DatePicker in D:/myapp/node_modules/angular-io-datepicker/src/datepicker/datePi
cker.d.ts

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in 'D:\myapp\src'
 @ ./src/main.ts 4:0-74
 @ multi ./src/main.ts

Datepicker module that it is complaining about it an external module (https://www.npmjs.com/package/angular-io-datepicker).

Can someone please suggest what could potentially be wrong and how could I resolve it?


回答1:


According to this here:

https://github.com/qdouble/angular-webpack2-starter#aot--donts

and here:

https://github.com/rangle/angular-2-aot-sandbox#func-in-providers-top

One of the types of things that Angular cannot statically analyze are functions being called in providers.

Looking at the library you have:

https://github.com/rd-dev-ukraine/angular-io-datepicker/blob/master/src/datepicker/datePicker.d.ts

It looks like there is this line here for the Component providers

providers: [ControlValueAccessorProviderFactory(DatePicker)

The ControlValueAccessorProviderFactory comes from here:

https://github.com/rd-dev-ukraine/angular-io-datepicker/blob/master/src/datepicker/common.ts

In this case we see that we're exporting a function that is being called directly in the providers array.

So I think that is causing the issues with static analysis, causing your build to fail. I think the library would have to change how they handle that for your program to compile.




回答2:


There was a bug with @angular/cli

It was fixed some time ago but workaround was to install after npm install

npm i enhanced-resolve@3.3.0

about bug



来源:https://stackoverflow.com/questions/45397481/aot-and-minification-failing-in-angular-4-with-external-modules

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