Ng-zorro-antd: NzMessageService 打包(ng build --prod)发布后访问提示Cannot read property 'resolveComponentFactory' of undefined

Created on 16 Aug 2018  ·  19Comments  ·  Source: NG-ZORRO/ng-zorro-antd

Version

1.3.0

Environment

"@angular/core": "^6.0.3", "@angular/cli": "~6.0.8", "ng-zorro-antd": "^1.3.0",

Reproduction link

https://ng-zorro-antd-start.stackblitz.io

Steps to reproduce

ng build --prod打包后NzMessageService发布后访问提示Cannot read property 'resolveComponentFactory' of undefined

What is expected?

打包测试

What is actually happening?

把node_modules删除重新安装(npm),都试了一下,ng build 是没有问题,加上--prod打包后发布就提示:

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'resolveComponentFactory' of undefined
TypeError: Cannot read property 'resolveComponentFactory' of undefined

Other?

Most helpful comment

@vthinkxie 我试了快速上手并没有问题,我找到错误地方了。因为我在组件里这样做的:

@Component({
  selector: 'app-add',
  templateUrl: './add.component.html',
  styleUrls: ['./add.component.css'],
  providers: [NzMessageService]
})

取消providers: [NzMessageService]后打包(--prod)就没有问题了。

Works for me. Thanks.

All 19 comments

同问,从昨天折磨到今天,rm node_modules 后没有用,npm install 或者npm install 淘宝镜像问题都在😔

@Cyclone77 @hannahGu 请确保你的cli版本与angular core 的版本对齐,resolveComponentFactory 是 angular 函数,报错只可能是包之间的版本没对齐

@vthinkxie 可否发一个cli版本与angular core的版本(6.0+)可以不报错的版本?

@Cyclone77 ng-zorro-antd 的版本是没有任何问题的,
打包报错和 ng-zorro-antd 也没有任何关系,不是你使用ng-zorro-antd后所有的报错都是 ng-zorro-antd 的问题
请仔细检查你本地的 angular 各个版本和 cli 版本,或者重新生成一个最小项目进行验证

你看到的 ng.ant.design 官网就是使用ng-zorro-antd的发布版本 angular的最新版本打包生成的
所有的打包过程也是完全公开的,日志可查,上次成功打包是4个小时之前
https://travis-ci.org/NG-ZORRO/ng-zorro-antd/jobs/417167992

@vthinkxie 没搞懂 “请确保你的cli版本与angular core 的版本对齐”啥意思,我今天又试了一下,把angular core和cli都升级到最新:"@angular/core": "^6.1.3", "@angular/cli": "~6.1.4",还是不行,难道这个版本没对齐?我整个项目就只用了ng-zorro-antd。

    private message: NzMessageService
        this.message.create('success', `文章内容保存成功。`);

我这里如果打包前(加--prod参数)把上面的代码:this.message.create('success', '文章内容保存成功。'); 屏蔽就没有问题,不屏蔽就报错!
` ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'resolveComponentFactory' of undefined TypeError: Cannot read property 'resolveComponentFactory' of undefined

@Cyclone77 https://ng.ant.design/docs/getting-started/zh 按照快速上手重新建一个新项目,然后用NzMessageService打包后也会有问题么?

@vthinkxie 我并没有非正常操作都是简单步骤,我直接用 cli ng new 建立的项目, 然后安装的ng-zorro-antd。而且其他组件都用的很好,唯独msg。

@Cyclone77 严格按照快速上手新建完项目,如果还是报错,你可以把你的项目上传到github上,然后给我地址

@vthinkxie 好的我来试试。

@vthinkxie 我试了快速上手并没有问题,我找到错误地方了。因为我在组件里这样做的:

@Component({
  selector: 'app-add',
  templateUrl: './add.component.html',
  styleUrls: ['./add.component.css'],
  providers: [NzMessageService]
})

取消providers: [NzMessageService]后打包(--prod)就没有问题了。

@Cyclone77 碰到问题提供可靠的重现链接是解决问题的最快速的方式,绝大部分的这种issue通过写重现链接都可以发现实际的问题。

@vthinkxie 感谢,没做重现链接是因为,我这边打开过慢……

@Cyclone77 自己动手重写一下也可以发现大部分问题的

@vthinkxie 并非调试问题,而且打包加了参数才错误,就没去想其它问题;耽误你时间了,再次感到抱歉。

@Cyclone77 @vthinkxie 两位好,我也遇到这个问题,当NzMessageService注册到module或component后使用aot打包会出现。也就是说NzMessageService不需要且不能注册到module或component是么?

@Yestory 我测试了,确实不需要注册。

我也正常跑起来了,按照前面同学说的去掉app.module下providers里面的NzMessageService就好了,全局angular/cli卸载了也可以。

@vthinkxie 我试了快速上手并没有问题,我找到错误地方了。因为我在组件里这样做的:

@Component({
  selector: 'app-add',
  templateUrl: './add.component.html',
  styleUrls: ['./add.component.css'],
  providers: [NzMessageService]
})

取消providers: [NzMessageService]后打包(--prod)就没有问题了。

Works for me. Thanks.

@vthinkxie 我试了快速上手并没有问题,我找到错误地方了。因为我在组件里这样做的:

@Component({
  selector: 'app-add',
  templateUrl: './add.component.html',
  styleUrls: ['./add.component.css'],
  providers: [NzMessageService]
})

取消providers: [NzMessageService]后打包(--prod)就没有问题了。

有效

Was this page helpful?
0 / 5 - 0 ratings