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.

Heroku リリースエラー知見集

Last updated at Posted at 2023-11-25

1.git push heroku masterでエラーが起きる方へ

エラー①

The Ruby version you are trying to install does not exist on this stack.
You are trying to install ruby-2.6.5 on heroku-20.
Ruby ruby-2.6.5 is present on the following stacks:
cedar-14, heroku-18

手順1:コマンドプロンプトで以下を実行

heroku stack:set <stackname>

stacknameRuby ruby-2.6.5 is present on the following stacks:のエラーの後ろに書かれているものを実行して下さい。

当記事のエラー文の場合、stacknameheroku-16になるためコマンドは以下のようになります。

コマンドプロンプト
 heroku stack:set heroku-18

完了したら再度

コマンドプロンプト
git push heroku master

参考記事①


エラー②

Node.js v20.9.0
       Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/
       Exiting!

手順1:以下をコマンドプロンプトで順に実行

コマンドプロンプト
 yarn install

エラー③

The engine "node" is incompatible with this module. Expected version "16.19.0". Got "20.9.0" error Found incompatible module..

手順1:以下をコマンドプロンプトで順に実行

コマンドプロンプト
heroku buildpacks:add heroku/nodejs #必要な人のみ
heroku buildpacks:add heroku/ruby
手順2:package.jsonの内容変更

以下の文をpackage.jsonに追記

package.json
  "engines": {
    "node": "16.19.0"
  },

追加後完成形のpackage.json

package.json
{
  "name": "自分のアプリ名",
  "private": true,
  "dependencies": {
    "@babel/plugin-proposal-private-methods": "^7.18.6",
    "@babel/plugin-proposal-private-property-in-object": "^7.21.0",
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "5.4.4",
    "babel-loader": "^8.2.2",
    "turbolinks": "^5.2.0",
    "webpack": "4.46.0",
    "webpack-cli": "3.3.12"
  },
  "version": "0.1.0",
  "devDependencies": {
    "@babel/plugin-proposal-private-methods": "^7.18.6",
    "@babel/plugin-proposal-private-property-in-object": "^7.21.0",
    "babel-loader": "^8.2.2",
    "webpack-dev-server": "3"
  },
  "engines": {
    "node": "16.19.0"
  },
  "packageManager": "yarn@1.22.19"
}
手順3:コマンドプロンプトで以下を実行
コマンドプロンプト
npm install
rails webpacker:install
rails webpacker:compile

エラー④

 Build failed
remote:  !     Two different lockfiles found: package-lock.json and yarn.lock
remote:
remote:        Both npm and yarn have created lockfiles for this application,
remote:        but only one can be used to install dependencies. Installing
remote:        dependencies using the wrong package manager can result in missing
remote:        packages or subtle bugs in production.
remote:
remote:        - To use npm to install your application's dependencies please delete
remote:          the yarn.lock file.
remote:
remote:          $ git rm yarn.lock
remote:
remote:        - To use yarn to install your application's dependencies please delete
remote:          the package-lock.json file.
remote:
remote:          $ git rm package-lock.json
remote:
remote:        https://help.heroku.com/0KU2EM53
remote:
remote:  !     Push rejected, failed to compile Node.js app.
remote:
remote:  !     Push failed

指示に従い、yarn.lockファイルを削除するため、コマンドプロンプトで以下を実行します。

コマンドプロンプト
git rm yarn.lock

アプリのファイルの内容が書き換わりますので、gitにあげるところからやりなおします。
以下を実行して下さい。

コマンドプロンプト
git add -A
git commit -m "yarn.lock削除"
git push heroku master

エラー⑤

コマンドプロンプト
node:internal/modules/cjs/loader:936
  throw err;
  ^
Error: Cannot find module '/Users/franciscomendes/.yarn/releases/yarn-berry.cjs'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:79:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Check if you have an .yarnrc file in your repo, if you have it, just delete it and try to run yarn and must work

手順1:.yarnrcを削除

.yarnrcはリリースの妨げになりますので、ファイルが存在する方は削除しましょう。

アプリのファイルの内容が書き換わりますので、gitにあげるところからやりなおします。
以下を実行して下さい。

コマンドプロンプト
git add -A
git commit -m "yarn.rc削除"
git push heroku master

エラー⑤

コマンドプロンプト
ArgumentError: Unknown migration version "7.0"; expected one of "4.2", "5.0", "5.1", "5.2", "6.0", "6.1"
手順1:

自分のプロダクトのマイグレーションファイルのActiveRecord::Migration[6.1][]の数値がすべて同じかチェックします。
上記のエラーの場合、6.1でなければいけないのにも関わらず、7.0が紛れているようですので、6.1にそろえてあげます。

※マイグレーションファイルを編集する際は必ずdownにしてから行うようにしてください

手順2:

再度git pushを行います。

コマンドプロンプト
git add -A
git commit -m "マイグレーションファイルバージョン変更"
git push heroku master

エラー⑥

コマンドプロンプト
error: src refspec master does not match any
error: failed to push some refs to 'https://git.heroku.com/アプリ名.git'
手順1:

GitHubのメインブランチがmasterではなくmainなのでそれに合わせてgitpushの最後のコマンドを変更します。

変更前
コマンドプロンプト
git push heroku master
変更後
コマンドプロンプト
git push heroku main

エラー⑦

コマンドプロンプト
 Error: Cannot find package '@babel/plugin-proposal-private-methods' imported from /tmp/build_e5431190/babel-virtual-resolve-base.js
           at new NodeError (/tmp/build_e5431190/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:203:5)
           at packageResolve (/tmp/build_e5431190/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:873:9)
           at moduleResolve (/tmp/build_e5431190/node_modules/@babel/core/lib/vendor/import-meta-resolve.js:902:20)
           at defaultResolve...
           (中略)
        ....{
         code: 'ERR_MODULE_NOT_FOUND'
       }
       

 !
 !     Precompiling assets failed.
 !
 !     Push rejected
手順1:以下をpackage.jsonのdependenciesに追記
package.json
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-proposal-private-property-in-object": "^7.21.0",

追加後完成形のpackage.json

package.json
{
  "name": "自分のアプリ名",
  "private": true,
  "dependencies": {
    "@babel/plugin-proposal-private-methods": "^7.18.6",
    "@babel/plugin-proposal-private-property-in-object": "^7.21.0",
    "@rails/actioncable": "^6.0.0",
    "@rails/activestorage": "^6.0.0",
    "@rails/ujs": "^6.0.0",
    "@rails/webpacker": "5.4.4",
    "babel-loader": "^8.2.2",
    "turbolinks": "^5.2.0",
    "webpack": "4.46.0",
    "webpack-cli": "3.3.12"
  },
  "version": "0.1.0",
  "devDependencies": {
    "@babel/plugin-proposal-private-methods": "^7.18.6",
    "@babel/plugin-proposal-private-property-in-object": "^7.21.0",
    "babel-loader": "^8.2.2",
    "webpack-dev-server": "3"
  },
  "engines": {
    "node": "16.19.0"
  },
  "packageManager": "yarn@1.22.19"
}
手順2:以下をコマンドプロンプトで実行
コマンドプロンプト
npm install
rails webpacker:install
rails webpacker:compile

アプリのファイルの内容が書き換わりますので、gitにあげるところからやりなおします。
以下を実行して下さい。

コマンドプロンプト
git add -A
git commit -m "package.json変更"
git push heroku master

2.デプロイはできているのにページが開かない方へ

1枚目と2枚目でやることが違いますので注意して下さい!

スクリーンショット (104).png

image_480.png

1枚目の写真が出る方へ

スクリーンショット (104).png
buildが上手くいっていません。herokuのダッシュボードのログ、 またはheroku logs --tailで出力されるログを見てエラーを解決後、再度
以下のコマンドを順に実行し、再デプロイしてみましょう。

コマンドプロンプト
git add -A

git commit -m "○○.index.erbを修正" #変更内容のメッセージを付けましょう。

git push heroku master

2枚目の写真が出る方へ

image_480.png
データベース周り、またはローカル環境のエラーが起きています。
コマンドプロンプトにて以下を実行してください。
エラーのログを見ることが出来ます

コマンドプロンプト
 heroku logs --tail

基本的にローカル上のエラーでリリースが出来てないことが多いです。ログをよく見てエラーの意味をしっかり理解して修正を行いましょう。

以下の記事も参考にしてみて下さい。
デプロイエラー対応まとめ

エラーが解決できたら以下のコマンドを順に実行し、再デプロイしてみましょう。

コマンドプロンプト
git add -A

git commit -m "○○.index.erbを修正" #変更内容のメッセージを付けましょう。

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?