Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 1 year has passed since last update.

git push heroku master のエラー解決集 for mac

Posted at

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のバージョンを指定する。

package.json
  "engines": {
    "node": "16.20.2",
    "npm": "8.19.4"
  }

変更したファイルをステージングする。

ターミナル
$ git add .

ステージングされたファイルをコミットする。

ターミナル
$ git commit -m "package.json fix"

herokuのBuildpackにnodeを追加していなければ、追加してからプッシュする。

  1. Herokuのアプリ設定を開く
  2. Settingsタブを開く
  3. Buildpacksの項目で add buildpacks でnodejsを追加する
    以下のように、nodejsが一番上に来るようにする。

screenshot 2023-11-25 14.37.26.jpg

上記のあと、以下で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
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?