简体   繁体   English

Aular和minification在Angular 4中与外部模块失败

[英]Aot and minification failing in Angular 4 with external modules

I am using Angular CLI to build an Angular 4 app. 我正在使用Angular CLI构建一个Angular 4应用程序。 Before deployment to prod, I would like to do aot and minification. 在部署到prod之前,我想做一个小的和缩小。 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 ). Datepicker模块,它抱怨它是一个外部模块( https://www.npmjs.com/package/angular-io-datepicker )。

Can someone please suggest what could potentially be wrong and how could I resolve it? 有人可以建议可能出现的问题,我该如何解决?

According to this here: 根据这里这个:

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

and here: 和这里:

https://github.com/rangle/angular-2-aot-sandbox#func-in-providers-top 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 . Angular无法静态分析的一类事物是在providers中调用的函数。

Looking at the library you have: 看看你有的图书馆:

https://github.com/rd-dev-ukraine/angular-io-datepicker/blob/master/src/datepicker/datePicker.d.ts 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 看起来这里有Component providers这一行

providers: [ControlValueAccessorProviderFactory(DatePicker)

The ControlValueAccessorProviderFactory comes from here: ControlValueAccessorProviderFactory来自这里:

https://github.com/rd-dev-ukraine/angular-io-datepicker/blob/master/src/datepicker/common.ts 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. 在这种情况下,我们看到我们正在导出一个直接在providers数组中调用的函数。

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. 我认为库必须改变它们处理程序编译的方式。

There was a bug with @angular/cli @ angular / cli有一个错误

It was fixed some time ago but workaround was to install after npm install 它已经修复了一段时间,但解决方法是在npm install之后安装

npm i enhanced-resolve@3.3.0 npm i enhanced-resolve@3.3.0

about bug 关于bug

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM