0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Node version upgrade & npm package update

Last updated at Posted at 2025-09-02

1. Node バージョンアップ

nvm install 22
nvm use 22
node -v # バージョン確認
  • node_modules は一旦削除するのが安全
rm -rf node_modules

2. 既存依存関係のインストール

npm install
  • Node 22 で動作するか確認するため、まずはこの状態でビルドやテストを実行します
npm run build
npm test

3. 古いパッケージの確認(マイナー/パッチアップデート)

npm outdated      # 古いパッケージを一覧表示
ncu -u -t patch   # package.json のパッチアップデートを適用
npm install       # package-lock.json を更新してインストール
  • ビルド・テストを実行して問題がないことを確認
npm run build
npm test
  • 問題なければコミット(パッチは後方互換性ありのためおそらく問題は起きない)
git add package.json package-lock.json
git commit -m "update patch dependencies"
  • マイナーアップデート
npm outdated      # 古いパッケージを一覧表示
ncu -u -t minor   # package.json のマイナーアップデートを適用
npm install       # package-lock.json を更新してインストール
  • ビルド・テストを実行して問題がないことを確認
npm run build
npm test
  • 問題なければコミット(マイナーは後方互換性ありのためおそらく問題は起きない)
git add package.json package-lock.json
git commit -m "update minor dependencies"

4. メジャーアップデート(1つずつまたは安全順序で)

npm install <package-name>@latest  # パッケージを個別にメジャーアップデート
  • ビルド・テストを実行
npm run build
npm test
  • 問題があれば修正(公式ドキュメント, changelog、migration guideなどを読み、破壊的変更の内容を確認し、コードを編集)
  • 修正後にコミット
git add .
git commit -m "update major dependencies and fix issues"

まとめ

💡 まとめると:

  1. Node 22 に切り替え
  2. node_modules 削除 → npm install
  3. マイナー/パッチ更新 → npm install → build / test → fix → commit
  4. メジャー更新 → npm install → build / test → fix → commit
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?