ionic build 正常
ionic build -- prod报错。报错日志如下:
ionic-app-script task: "build"
[09:10:58] Error: Cannot find module '@angular/compiler-cli/ngtools2'
Error: Cannot find module '@angular/compiler-cli/ngtools2'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:587:15)
at Function.Module._load (internal/modules/cjs/loader.js:513:25)
at Module.require (internal/modules/cjs/loader.js:643:17)
at require (internal/modules/cjs/helpers.js:22:18)
at xxxx\npm\node_modules\@ionic\app- scripts\dist\aot\aot-compiler.js:206:90
1、工厂模式下,ngc压缩文件的时候报错,网络上的命令对我不生效,但是可能对其他人生效,主要命令如下:
npm install @angular/compiler@latest --save
npm install @angular/compiler-cli@latest --save
npm i @ionic/app-scripts
npm uninstall -g angular-cli
npm cache clean or npm cache verify (if npm > 5)
npm install -g @angular/cli@latest
以上命令呢其实就是更新当前的编译命令到最新,让他适配最新的依赖报;
2、然后一顿操作之后:把node_modules删除重新安转一下;可以手动删除,也可命令删除,命令如下;
1、rm -r node_modules(或node_modules手动删除您的文件夹)
2、npm cache clean --force(清空npm缓存)
3、npm install 或者 cnpm install (安装依赖)
部分同学搞完第一步骤之后直接执行ionic build -- prod可能报错如下错误:
[14:55:18] typescript error
Error during template compile of 'RoundProgressModule' Function calls are not supported in decorators in
'NgModule' 'NgModule' calls a function at @angular/core/core.ts(194,50).
[14:55:18] ionic-app-script task: "build"
[14:55:18] Error: The Angular AoT build failed. See the issues above
Error: The Angular AoT build failed. See the issues above
at /Users/xxx/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:237:55
at step (/Users/xxx/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:32:23)
at Object.next (/Users/xxx/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:13:53)
at fulfilled (/Users/xxx/node_modules/@ionic/app-scripts/dist/aot/aot-compiler.js:4:58)
[ERROR] An error occurred while running subprocess ionic-app-scripts.
这里该怎么办呢,重复一下第二步骤就行,依赖报没有下载安装。
以下是我的处理方式:
打开项目的package.json文件,主要对比以下信息:
"dependencies": {
"@angular/animations": "5.2.11",
"@angular/common": "5.2.11",
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
"@angular/forms": "5.2.11",
"@angular/http": "5.2.11",
"@angular/platform-browser": "5.2.11",
"@angular/platform-browser-dynamic": "5.2.11",
此处的版本号一定要一致,一定要一致,一定要一致 。。。
尤其这三
"@angular/compiler": "5.2.11",
"@angular/compiler-cli": "5.2.11",
"@angular/core": "5.2.11",
然后重新执行一切就OK了!大功告成!!!退!!!!
【总结】:
第一步的几个操作虽然更新了编译器的最新版本,但是不一定和项目信息相匹配,所以一定要查看此信息,这里是关键呢!全局的版本可以是最新的,但是项目里面的一定要一致!不能盲目升级到最新版本。