Failed to install gems via Bundler
以下のようなエラーが出たときの対処法
remote: Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
remote: Your bundle only supports platforms ["arm64-darwin-22"] but your local platform
remote: is x86_64-linux. Add the current platform to the lockfile with
remote: `bundle lock --add-platform x86_64-linux` and try again.
remote: Bundler Output: Your bundle only supports platforms ["arm64-darwin-22"] but your local platform
remote: is x86_64-linux. Add the current platform to the lockfile with
remote: `bundle lock --add-platform x86_64-linux` and try again.
remote:
remote: !
remote: ! Failed to install gems via Bundler.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to release-test.
remote:
To https://git.heroku.com/release-test.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/release-test.git'
まずは原因を理解する。エラーに以下のような文が出力されている。
remote: Your bundle only supports platforms ["arm64-darwin-22"] but your local platform
remote: is x86_64-linux. Add the current platform to the lockfile with
remote: `bundle lock --add-platform x86_64-linux` and try again.
つまり原因は、ローカル環境が x86_64-linux であるのにも関わらず、bundle は arm64-darwin-22 しかサポートしていないことである。
次に解決法を考える。エラーに以下のような文が出力されている。
remote: `bundle lock --add-platform x86_64-linux` and try again.
なので、ここに書いてあるとおりに以下を実行する。
$ bundle lock --add-platform x86_64-linux
このコマンドによってGemfile.lockが変更されたので、ステージングする。
$ git add .
次に、ステージしたGemfile.lockをコミットする。
$ git commit -m "Gemfile.lock fix"
最後に、herokuへプッシュする。
$ git push heroku master
Precompiling assets failed
以下のようなエラーが出たときの対処法
remote: Error: error:0308010C:digital envelope routines::unsupported
remote: at new Hash (node:internal/crypto/hash:68:19)
remote: at Object.createHash (node:crypto:138:10)
remote: at CompressionPlugin.taskGenerator (/tmp/build_0a6c1434/node_modules/compression-webpack-plugin/dist/index.js:163:38)
remote: at taskGenerator.next (<anonymous>)
remote: at /tmp/build_0a6c1434/node_modules/compression-webpack-plugin/dist/index.js:216:49
remote: at CompressionPlugin.runTasks (/tmp/build_0a6c1434/node_modules/compression-webpack-plugin/dist/index.js:236:9)
remote: at /tmp/build_0a6c1434/node_modules/compression-webpack-plugin/dist/index.js:270:18
remote: at _next0 (eval at create (/tmp/build_0a6c1434/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:37:17)
remote: at eval (eval at create (/tmp/build_0a6c1434/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:53:1)
remote: at WebpackAssetsManifest.handleEmit (/tmp/build_0a6c1434/node_modules/webpack-assets-manifest/src/WebpackAssetsManifest.js:486:5)
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_0a6c1434/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:49:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_0a6c1434/node_modules/tapable/lib/Hook.js:154:20)
remote: at Compiler.emitAssets (/tmp/build_0a6c1434/node_modules/webpack/lib/Compiler.js:491:19)
remote: at onCompiled (/tmp/build_0a6c1434/node_modules/webpack/lib/Compiler.js:278:9)
remote: at /tmp/build_0a6c1434/node_modules/webpack/lib/Compiler.js:681:15
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_0a6c1434/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_0a6c1434/node_modules/tapable/lib/Hook.js:154:20)
remote: at /tmp/build_0a6c1434/node_modules/webpack/lib/Compiler.js:678:31
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_0a6c1434/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_0a6c1434/node_modules/tapable/lib/Hook.js:154:20)
remote: at /tmp/build_0a6c1434/node_modules/webpack/lib/Compilation.js:1423:35
remote: at AsyncSeriesHook.eval [as callAsync] (eval at create (/tmp/build_0a6c1434/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
remote: at AsyncSeriesHook.lazyCompileHook (/tmp/build_0a6c1434/node_modules/tapable/lib/Hook.js:154:20)
remote: at /tmp/build_0a6c1434/node_modules/webpack/lib/Compilation.js:1414:32
remote: at eval (eval at create (/tmp/build_0a6c1434/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:14:1)
remote: at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
remote:
remote:
remote: !
remote: ! Precompiling assets failed.
remote: !
remote: ! Push rejected, failed to compile Ruby app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to release-test.
remote:
To https://git.heroku.com/release-test.git
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/release-test.git'
Error: error:0308010C:digital envelope routines::unsupported
上のエラー文で検索をかけたところ、どうやらNodeのバージョンが悪さをしているらしい。
ちなみに今の環境は以下である。
$ node -v
v20.4.0
$ npm -v
9.7.2
解決方法1
package.jsonでnodeとnpmのバージョンを指定する。
まず、以下のコマンドで自分のnodeとnpmのバージョンを確認する。
$ node -v
$ npm -v
package.jsonファイルを編集する。以下を付け加える。このとき、先程確認したnodeとnpmのバージョンを指定する。
"engines": {
"node": "16.20.2",
"npm": "8.19.4"
}
変更したファイルをステージングする。
$ git add .
ステージングされたファイルをコミットする。
$ git commit -m "package.json fix"
herokuのBuildpackにnodeを追加していなければ、追加してからプッシュする。
- Herokuのアプリ設定を開く
- Settingsタブを開く
- Buildpacksの項目で add buildpacks でnodejsを追加する
以下のように、nodejsが一番上に来るようにする。
上記のあと、以下でherokuにプッシュする。
$ git push heroku master
解決方法2
nodeのバージョンを下げて対応してみる。今回は、バージョン16系に落とした。
ますはnodeバージョン16系をインストールする。
$ brew install node@16
現在紐づいているインストール済みのバージョンを解除する。
$ brew unlink node
使用したいバージョンを紐付ける。今回は、16系にしたいので、以下のコマンドを実行した。
$ brew link --overwrite node@16
すると、以下のように出力されたので、言われたとおりにechoを実行する。
Linking /opt/homebrew/Cellar/node@16/16.20.2... 1864 symlinks created.
If you need to have this software first in your PATH instead consider running:
echo 'export PATH="/opt/homebrew/opt/node@16/bin:$PATH"' >> ~/.zshrc
以下の通り実行した。これは、人によって違う可能性があるので自分のターミナルからコピーして実行するのがオススメです。
$ echo 'export PATH="/opt/homebrew/opt/node@16/bin:$PATH"' >> ~/.zshrc
もう一度以下を実行すると、nodeのバージョンが16系に下がっているはずである。
$ brew link --overwrite node@16
Warning: Already linked: /opt/homebrew/Cellar/node@16/16.20.2
To relink, run:
brew unlink node@16 && brew link --force node@16
バージョンがちゃんと下がっているのか確認する。
$ node -v
v16.20.2
16系に下がっていたので、もう一度herokuにプッシュする。
$ git push heroku master