Angular 9 Ivy - 泛型类型 'ɵɵFactoryDef' 需要2个类型参数

29

看起来Angular Ivy还没有准备好。我正在尝试使用ivy构建我的项目,这是Angular 9的主要思想。许多库与此功能不兼容,其中一个库是@angular/flex-layout。Material和service-worker也有相同的问题。

在使用ng build --prod --aot -c=production脚本构建我的项目后,我得到了:

                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/core/typings/media-trigger/media-trigger.d.ts:71:18 - error TS2314: Generic type 'ɵɵFactoryDef' requires 2 type argument(s).

71     static ɵfac: ɵngcc0.ɵɵFactoryDef<MediaTrigger>;
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/extended/typings/show-hide/show-hide.d.ts:18:18 - error TS2314: Generic type 'ɵɵFactoryDef' requires 2 type argument(s).

18     static ɵfac: ɵngcc0.ɵɵFactoryDef<ShowHideStyleBuilder>;
                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/@angular/flex-layout/extended/typings/show-hide/show-hide.d.ts:49:18 - error TS2314: Generic type 'ɵɵFactoryDef' requires 2 type argument(s).

49     static ɵfac: ɵngcc0.ɵɵFactoryDef<ShowHideDirective>;

这个错误比我上面写的还要长,在搜索这个问题时我花了很多时间,但桌面上没有任何效果,除了禁用 ivy 这个选项,这并不是一个好的选择。

3个回答

28

幸运的是,Angular 9.1已经发布并解决了这个问题。通过运行ng update @angular/cli @angular/core升级到9.1后,我删除了我的node_modules并重新安装。然后我将typescript从3.7.5升级到3.8.3。现在ngcc正常工作,构建后没有错误。

更多信息请查看:Angular Version 9.1


1
你的完整的 postinstall 命令是什么?它只有 "postinstall":"ngcc" 吗? - harishr
@harishr 是的,它是“ngcc”。如果你正在升级,请不要使用入口点。只需保持 ngcc 即可。 - Yazan Mehrez
我仍然面临这个问题...不得不回退到9.0.5来解决这个问题。 - harishr
1
是的,我做了那个...我更新了TypeScript和所有其他包。删除了node_modules并重新安装了一切,但仍然得到与您在问题中提到的完全相同的错误。我需要清除全局缓存吗? - harishr
3
是的,删除node_modules和运行npm cache verify对我起了作用。 - Mattijs
显示剩余2条评论

2

如果您使用 ng update @angular/cli @angular/core 命令时遇到以下错误:

错误:存储库不干净。在更新之前,请提交或隐藏任何更改。

请使用以下命令:

ng update @angular/cli @angular/core --allow-dirty

1

在我的情况下,完全删除node_modules文件夹并运行npm install后,它就可以正常工作了。


谢谢,这对我有用。我已经导入了@angular/cdk/scrolling并遇到了同样的问题! - Mekey Salaria

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接