1. 升级angular-cli
1.1 卸载旧的angular-cli
首先先卸载一下,以防万一。
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
1.2 操作全局angular-cli
npm uninstall -g @angular/cli
npm cache verify
# if npm version is < 5 then use `npm cache clean`
npm install -g @angular/cli@latest
1.3 操作本地的angular-cli
rm -rf node_modules dist # use rmdir /S/Q node_modules dist in Windows Command Prompt; use rm -r -fo node_modules,dist in Windows PowerShell
npm install --save-dev @angular/cli@latest
npm install
经过这样的操作之后,使用命令
ng version
查看angular-cli的版本。
2. 升级angular
为了防止出现问题"UNMET PEER DEPENDENCY"
先运行下面三条命令:
rm -rf node_modules/
npm cache clean
npm install
我是从angular4.3.6升级到angular5.2.8
运行下面的命令:
npm install @angular/{animations,common,compiler,core,forms,http,platform-browser,platform-browser-dynamic,router}@latest --save
npm install --save core-js@latest rxjs@latest zone.js@latest
npm install --save-dev @angular/{compiler-cli,cli,language-service}@latest
npm install --save-dev @types/{jasmine,jasminewd2,node}@latest
npm install --save-dev codelyzer@latest jasmine-core@latest jasmine-spec-reporter@latest karma@latest karma-chrome-launcher@latest karma-cli@latest karma-coverage-istanbul-reporter@latest karma-jasmine@latest karma-jasmine-html-reporter@latest protractor@latest ts-node@latest tslint@latest
npm install --save-dev typescript@2.4.2
运行这些命令之后,
还有一个警告:
@angular/platform-server 4.3.6 UNMET PEER DEPENDENCY
的问题。这个时候,我是将"@angular/platform-server": "~4.3.6"改成"@angular/platform-server": "^5.2.8"。然后npm install,就可以了。
3. 出现的问题
../common/util/CustomErrorHandler.ts(11,9): error TS2554: Expected 0 arguments, but got 1.
将ErrorHandler的参数去掉就可以了。
出现Unknown option: '--environment'的提示:
https://github.com/angular/angular-cli/blob/master/docs/documentation/stories/application-environments.md
4. 参考地址
https://github.com/angular/angular-cli
https://stackoverflow.com/questions/36597780/how-do-i-correctly-upgrade-angular-2-npm-to-the-latest-version