- 此时不要盲目确定是ngmodel中哪个子模块出了问题,因为错误描述并没有详细跟踪到具体的错误地点,这里只是一个全局的描述“Can’t resolve './app.module.ngfactory”
- 由于是node_module执行过程出的问题,可以用此命令进行查看(build的时候会启动ngc):
./node_modules/.bin/ngc
显示详细描述信息为:
Error: Type TrustUrlPipe in /Users/path to… /ionic/xx/src/pipes/trust-url/trust-url.ts is part of the declarations of 2 modules: AppModule in /Users/path to…/ionic/xx/src/app/app.module.ts
and PipesModule in /Users/path to…/ionic/xx/src/pipes/pipes.module.ts!
Please consider moving TrustUrlPipe in /Users/path to…/ionic/xx/src/pipes/trust-url/trust-url.ts to a higher module that imports AppModule in /Users/path to …/ionic/xx/src/app/app.module.ts and PipesModule in /Users/path to…/ionic/xx/src/pipes/pipes.module.ts.
You can also create a new NgModule that exports and includes TrustUrlPipe in /Users/path
to…/ionic/xx/src/pipes/trust-url/trust-url.ts then import that NgModule
in AppModule in /Users/path to …/ionic/xx/src/app/app.module.ts and
PipesModule in /Users/path to …/ionic/xx/src/pipes/pipes.module.ts.
3.检查provider管道,的确在该目录下重复声明了一次ngModule
4.重新执行build --prod 发现还是会有错误,没有关系,继续跟踪ngc,查看详细错误,逐个解决掉就好了
5.记得加sudo执行build --prod 有些会因为权限问题导致build无法成功。
6.如果一直提示“Can’t resolve ‘./app.module.ngfactory’” ,请查看这里:https://github.com/ionic-team/ionic-app-scripts/issues/1309
解决办法:修改package.json中的@ionic-scripts的版本,更新查看npm的@ionic-scripts版本,再次执行。
如有帮助,无须言谢。
转载说明出处,感谢。