🍏

Codespaces の Node.js バージョンを変更

2022/02/07に公開

基本的には package.json に定義されている engine.node のバージョンが自動で適用されるようです。
ですが未定義だったり途中で変えたい場合もあるかと思います。
その場合は nvm が入っているのでそちらで切り替えます。

nvm install 16
nvm use --delete-prefix v16.13.2
ログ
@SnowCait ➜ /workspaces/sandbox (main ✗) $ node -v
v14.18.3
@SnowCait ➜ /workspaces/sandbox (main ✗) $ nvm --version
0.38.0
@SnowCait ➜ /workspaces/sandbox (main ✗) $ nvm use 16
N/A: version "16 -> N/A" is not yet installed.

You need to run "nvm install 16" to install it before using it.
@SnowCait ➜ /workspaces/sandbox (main ✗) $ nvm install 16
Downloading and installing node v16.13.2...
Downloading https://nodejs.org/dist/v16.13.2/node-v16.13.2-linux-x64.tar.xz...
############################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Your user’s .npmrc file (${HOME}/.npmrc)
has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.
Run `nvm use --delete-prefix v16.13.2` to unset it.
@SnowCait ➜ /workspaces/sandbox (main ✗) $ nvm use --delete-prefix v16.13.2
Now using node v16.13.2 (npm v8.1.2)
@SnowCait ➜ /workspaces/sandbox (main ✗) $ node --version
v16.13.2

Discussion