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>
stackname
はRuby ruby-2.6.5 is present on the following stacks:
のエラーの後ろに書かれているものを実行して下さい。
当記事のエラー文の場合、stackname
はheroku-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に追記
"engines": {
"node": "16.19.0"
},
追加後完成形の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に追記
"@babel/plugin-proposal-private-methods": "^7.18.6",
"@babel/plugin-proposal-private-property-in-object": "^7.21.0",
追加後完成形の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枚目でやることが違いますので注意して下さい!
1枚目の写真が出る方へ
buildが上手くいっていません。herokuのダッシュボードのログ、 またはheroku logs --tail
で出力されるログを見てエラーを解決後、再度
以下のコマンドを順に実行し、再デプロイしてみましょう。
git add -A
git commit -m "○○.index.erbを修正" #変更内容のメッセージを付けましょう。
git push heroku master
2枚目の写真が出る方へ
データベース周り、またはローカル環境のエラーが起きています。
コマンドプロンプトにて以下を実行してください。
エラーのログを見ることが出来ます
heroku logs --tail
基本的にローカル上のエラーでリリースが出来てないことが多いです。ログをよく見てエラーの意味をしっかり理解して修正を行いましょう。
以下の記事も参考にしてみて下さい。
▶デプロイエラー対応まとめ
エラーが解決できたら以下のコマンドを順に実行し、再デプロイしてみましょう。
git add -A
git commit -m "○○.index.erbを修正" #変更内容のメッセージを付けましょう。
git push heroku master