本文介绍了带有外部模块的 Angular 4 中的 Aot 和缩小失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Angular CLI 构建一个 Angular 4 应用程序.在部署到 prod 之前,我想做 aot 和 minification.所以我执行了以下命令

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/

这给了我以下错误

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 模块,它抱怨它是一个外部模块 (https://www.npmjs.com/package/angular-io-datepicker).

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?

推荐答案

根据这里:

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

这里:

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

Angular 无法静态分析的一种类型是在 providers 中调用的函数.

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

看看你拥有的图书馆:

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

Component providers

providers: [ControlValueAccessorProviderFactory(DatePicker)

ControlValueAccessorProviderFactory 来自这里:

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

在本例中,我们看到我们正在导出一个直接在 providers 数组中调用的函数.

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.

这篇关于带有外部模块的 Angular 4 中的 Aot 和缩小失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 16:10
查看更多