Angular 更新 Node.js 、npm 與 Angular CLI

查看 Node.js 版本

使用指令:node -v


更新 Node.js版本

使用指令:choco upgrade nodejs-lts -y (需安裝 https://chocolatey.org/)

Chocolatey v0.10.15
Upgrading the following packages:
nodejs-lts
By upgrading you accept licenses for the packages.
nodejs-lts is not installed. Installing...

nodejs-lts v16.14.2 [Approved]
nodejs-lts package files upgrade completed. Performing other installation steps.
Installing 64 bit version
Installing nodejs-lts...
nodejs-lts has been installed.
  nodejs-lts may be able to be automatically uninstalled.
Environment Vars (like PATH) have changed. Close/reopen your shell to
 see the changes (or in powershell/cmd.exe just type `refreshenv`).
 The upgrade of nodejs-lts was successful.
  Software installed as 'MSI', install location is likely default.

Chocolatey upgraded 1/1 packages.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Did you know the proceeds of Pro (and some proceeds from other
 licensed editions) go into bettering the community infrastructure?
 Your support ensures an active community, keeps Chocolatey tip top,
 plus it nets you some awesome features!
 https://chocolatey.org/compare





查看 npm 版本

使用指令:npm -v

畫面顯示目前的  npm 版本為 7.19.0



更新 npm 版本

使用指令:npm update -g 但出現一堆錯誤訊息:

npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/angular-realworld-advanced - Not found
npm ERR! 404
npm ERR! 404  'angular-realworld-advanced@*' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2022-03-23T03_50_58_721Z-debug.log


改用這個指令:npm install npm@latest -g

等待指令完成後,畫面顯示:
removed 227 packages, changed 20 packages, and audited 31 packages in 4s
found 0 vulnerabilities

再次查看 npm 版本,使用指令:npm -v

畫面顯示目前的  npm 版本為 8.5.5

更新成功!



查看 Angular 版本

使用指令:ng version

Angular CLI: 11.0.2
Node: 16.14.2
OS: win32 x64

Angular: undefined
...
Ivy Workspace: <error>

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1100.2
@angular-devkit/core         11.0.2
@angular-devkit/schematics   11.0.2
@angular/cli                 11.0.2
@schematics/angular          11.0.2
@schematics/update           0.1100.2




查看 Angular 可更新的版本

可先告官網查看升級的步驟:https://update.angular.io/

使用指令:ng update

會將可使用的更新列出來,如下方紅色區域

The installed local Angular CLI version is older than the latest stable version.
Installing a temporary version to perform the update.
Installing packages for tooling via npm.
Installed packages for tooling via npm.
Using package manager: 'npm'
Collecting installed dependencies...
Found 1 dependencies.
    We analyzed your package.json, there are some packages to update:
      Name          Version                  Command to update
     -----------------------------------------------------------
      @angular/cli  11.0.2 -> 12.2.9         ng update @angular/cli@12
    There might be additional packages which don't provide 'ng update' capabilities that are outdated.
    You can update the additional packages by running the update command of your package manager.




更新 Angular CLI 版本

使用指令:ng update @angular/cli@12 --force

如果 Migration failed,可再指令後面加 --force 試試

若遇到 Repository is not clean. Please commit or stash any changes before updating.

記得將自己的 git 儲存庫新增 commit 


重複執行 ng update,最後就可將 Angular CLI 更新至最新版

Angular CLI: 13.3.0
Node: 16.14.2
Package Manager: npm 8.5.5
OS: win32 x64

Angular: undefined
...

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.1303.0
@angular-devkit/core         13.3.0
@angular-devkit/schematics   13.3.0
@angular/cli                 13.3.0
@schematics/angular          13.3.0



留言

這個網誌中的熱門文章

CPE 一顆星選集題目說明與解答 - Java 筆記與心得分享

Visual Studio 自動排版格式化程式碼

1. Vito's family (CPE10406, UVA10041) - CPE一顆星解答與說明