從angular5 升級到angular9(最新版本)

搞了一天,終於升級成功了,其實最後升級成功倒發現沒那麼難。

以下方法適用於想一次性升級package.json中所有依賴到最新版本的方案:

  1. 這個庫是我們的必需品npm-check-updates
    依次運行下面的三個命令
npm i -g npm-check-updates
ncu -u
npm install
  1. 升級完之後可能會報這個錯誤
    The serve command requires to be run in an Angular project, but a project definition could not be found.
    在這裏插入圖片描述
    這個原因是新的angular cli更新使angular-cli.json變得多餘,並被angular.json代替。一般出現在比較老版本的angular cli中,我的就是1.6.6的版本,此時可以運行以下命令
ng update @angular/cli --migrate-only --from=<WhateverVersionYouAreCurrentlyOn>

比如我的之前版本爲1.6.6,需要運行以下命令

ng update @angular/cli --migrate-only --from=1.6.6

參考資料:

  1. https://stackoverflow.com/questions/16073603/how-do-i-update-each-dependency-in-package-json-to-the-latest-version
  2. https://stackoverflow.com/questions/53096996/angular-cli-error-the-serve-command-requires-to-be-run-in-an-angular-project-b
  3. https://github.com/angular/angular-cli/issues/12215#issuecomment-433593036
發佈了44 篇原創文章 · 獲贊 117 · 訪問量 28萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章