概要
VoltaでNode.jsのバージョンを管理している環境で、Amplifyを使用しているプロジェクトのNode.jsのバージョンを変更する際、プロジェクト直下の package.json
に書かれている volta.node
のバージョンを書き換えるだけでは、 amplify
コマンドを実行した際には変更前のNode.jsのバージョンが使用されてしまうようです。
具体的には amplify push
時に実行される yarn
で、インストールしようとしている環境のNode.jsのバージョンと、インストールしようとしているパッケージのバージョンがが合わないというエラーが出てしまいます。
Command failed with exit code 1: yarn --no-bin-links --production
warning ../../../package.json: No license field
error xxxxx@x.x.x: The engine "node" is incompatible with this module. Expected version "20 || >=22". Got "18.15.0"
error Found incompatible module.
yarn install v1.22.10
[1/4] Resolving packages...
[2/4] Fetching packages...
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
対応方法
@aws-amplify/cli
の再インストールで解決します。
volta uninstall @aws-amplify/cli
volta install @aws-amplify/cli
プロジェクトのNode.jsのバージョンがどこで保持されているのか、保持されているとしてなぜcliの再インストールで解決するのかはよくわかっていません。ご存じの方がおられればぜひコメントで教えてください。
参考
Error Node when i use amplify push · Issue #13218 · aws-amplify/amplify-cli
バージョン情報
amplify -v
12.10.1