herokuでのデプロイ
herokuでのデプロイ
herokuでのデプロイ時にエラーになり、つまってしまったので備忘録としてまとめます。
herokuデプロイ時のログは、以下のようになります。
-----> Building on the Heroku-22 stack -----> Determining which buildpack to use for this app ! Warning: Multiple default buildpacks reported the ability to handle this app. The first buildpack in the list below will be used. Detected buildpacks: Ruby,Node.js See https://devcenter.heroku.com/articles/buildpacks#buildpack-detect-order -----> Ruby app detected -----> Installing bundler 2.3.10 -----> Removing BUNDLED WITH version in the Gemfile.lock -----> Compiling Ruby/Rails -----> Using Ruby version: ruby-3.1.2 -----> Installing dependencies using bundler 2.3.10 Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4 Fetching gem metadata from https://rubygems.org/......... Fetching rake 13.0.6 Installing rake 13.0.6 Fetching concurrent-ruby 1.1.9 Fetching thread_safe 0.3.6 Fetching minitest 5.14.4 Fetching zeitwerk 2.4.2 Installing minitest 5.14.4 Installing thread_safe 0.3.6 Installing concurrent-ruby 1.1.9 Fetching builder 3.2.4 Installing zeitwerk 2.4.2 Fetching erubi 1.10.0 Installing builder 3.2.4 Fetching mini_portile2 2.6.1 Fetching racc 1.5.2 Installing erubi 1.10.0 Installing mini_portile2 2.6.1 Fetching crass 1.0.6 Fetching rack 2.2.3 Fetching nio4r 2.5.8 Installing rack 2.2.3 Installing crass 1.0.6 Fetching websocket-extensions 0.1.5 Installing racc 1.5.2 with native extensions Installing nio4r 2.5.8 with native extensions Installing websocket-extensions 0.1.5 Fetching marcel 1.0.2 Installing marcel 1.0.2 Fetching mini_mime 1.1.1 Fetching bcrypt 3.1.17 Installing mini_mime 1.1.1 Installing bcrypt 3.1.17 with native extensions Fetching msgpack 1.4.2 Installing msgpack 1.4.2 with native extensions Using bundler 2.3.10 Fetching coderay 1.1.3 Installing coderay 1.1.3 Using digest 3.1.0 Fetching faraday-em_http 1.0.0 Installing faraday-em_http 1.0.0 Fetching faraday-em_synchrony 1.0.0 Installing faraday-em_synchrony 1.0.0 Fetching faraday-excon 1.1.0 Installing faraday-excon 1.1.0 Fetching faraday-httpclient 1.0.1 Installing faraday-httpclient 1.0.1 Fetching multipart-post 2.1.1 Fetching faraday-net_http 1.0.1 Installing multipart-post 2.1.1 Installing faraday-net_http 1.0.1 Fetching faraday-net_http_persistent 1.2.0 Fetching faraday-patron 1.0.0 Installing faraday-net_http_persistent 1.2.0 Fetching faraday-rack 1.0.0 Installing faraday-patron 1.0.0 Fetching faraday-retry 1.0.3 Installing faraday-rack 1.0.0 Using ruby2_keywords 0.0.5 Fetching ffi 1.15.4 Installing faraday-retry 1.0.3 Fetching hpricot 0.8.6 Installing hpricot 0.8.6 with native extensions Installing ffi 1.15.4 with native extensions Fetching mini_magick 4.11.0 Installing mini_magick 4.11.0 Fetching jwt 2.3.0 Installing jwt 2.3.0 Fetching kaminari-core 1.2.2 Installing kaminari-core 1.2.2 Fetching matrix 0.4.2 Installing matrix 0.4.2 Fetching method_source 1.0.0 Installing method_source 1.0.0 Fetching multi_json 1.15.0 Installing multi_json 1.15.0 Fetching multi_xml 0.6.0 Installing multi_xml 0.6.0 Fetching timeout 0.3.0 Installing timeout 0.3.0 Fetching oauth 0.5.8 Installing oauth 0.5.8 Fetching pg 1.4.3 Installing pg 1.4.3 with native extensions Fetching psych 3.3.3 Installing psych 3.3.3 with native extensions Fetching thor 1.1.0 Installing thor 1.1.0 Fetching tilt 2.0.10 Installing tilt 2.0.10 Fetching temple 0.8.2 Installing temple 0.8.2 Fetching tzinfo 1.2.9 Installing tzinfo 1.2.9 Fetching i18n 1.8.10 Installing i18n 1.8.10 Fetching websocket-driver 0.7.5 Installing websocket-driver 0.7.5 with native extensions Fetching rack-test 1.1.0 Installing rack-test 1.1.0 Fetching rack-proxy 0.7.0 Installing rack-proxy 0.7.0 Fetching sprockets 4.0.2 Installing sprockets 4.0.2 Fetching mail 2.7.1 Installing mail 2.7.1 Fetching nokogiri 1.12.5 Installing nokogiri 1.12.5 with native extensions Fetching faraday-multipart 1.0.3 Installing faraday-multipart 1.0.3 Fetching puma 4.3.8 Installing puma 4.3.8 with native extensions Fetching pry 0.14.1 Installing pry 0.14.1 Fetching net-protocol 0.1.3 Installing net-protocol 0.1.3 Fetching bootsnap 1.9.1 Installing bootsnap 1.9.1 with native extensions Fetching slim 4.1.0 Installing slim 4.1.0 Fetching activesupport 6.0.4.1 Installing activesupport 6.0.4.1 Fetching ruby-vips 2.1.4 Installing ruby-vips 2.1.4 Fetching sassc 2.4.0 Installing sassc 2.4.0 with native extensions Fetching faraday 1.10.0 Installing faraday 1.10.0 Fetching pry-rails 0.3.9 Installing pry-rails 0.3.9 Fetching net-smtp 0.3.1 Installing net-smtp 0.3.1 Fetching globalid 0.5.2 Installing globalid 0.5.2 Fetching activemodel 6.0.4.1 Installing activemodel 6.0.4.1 Fetching jbuilder 2.11.2 Installing jbuilder 2.11.2 Fetching image_processing 1.12.2 Installing image_processing 1.12.2 Fetching oauth2 1.4.9 Installing oauth2 1.4.9 Fetching activejob 6.0.4.1 Installing activejob 6.0.4.1 Fetching activerecord 6.0.4.1 Installing activerecord 6.0.4.1 Fetching sorcery 0.16.3 Installing sorcery 0.16.3 Fetching kaminari-activerecord 1.2.2 Installing kaminari-activerecord 1.2.2 Fetching ransack 2.4.1 Installing ransack 2.4.1 Fetching html2slim 0.2.0 Installing html2slim 0.2.0 Fetching rails-dom-testing 2.0.3 Fetching loofah 2.12.0 Installing loofah 2.12.0 Installing rails-dom-testing 2.0.3 Fetching rails-html-sanitizer 1.4.2 Installing rails-html-sanitizer 1.4.2 Fetching actionview 6.0.4.1 Installing actionview 6.0.4.1 Fetching actionpack 6.0.4.1 Fetching kaminari-actionview 1.2.2 Installing kaminari-actionview 1.2.2 Fetching kaminari 1.2.2 Installing actionpack 6.0.4.1 Installing kaminari 1.2.2 Fetching actionmailer 6.0.4.1 Fetching activestorage 6.0.4.1 Fetching actioncable 6.0.4.1 Installing actionmailer 6.0.4.1 Installing activestorage 6.0.4.1 Installing actioncable 6.0.4.1 Fetching railties 6.0.4.1 Fetching sprockets-rails 3.2.2 Fetching actionmailbox 6.0.4.1 Installing railties 6.0.4.1 Installing sprockets-rails 3.2.2 Fetching actiontext 6.0.4.1 Installing actionmailbox 6.0.4.1 Installing actiontext 6.0.4.1 Fetching rails 6.0.4.1 Fetching rails-i18n 6.0.0 Fetching slim-rails 3.3.0 Installing rails 6.0.4.1 Installing slim-rails 3.3.0 Fetching webpacker 4.3.0 Installing rails-i18n 6.0.0 Installing webpacker 4.3.0 Fetching sassc-rails 2.1.2 Installing sassc-rails 2.1.2 Fetching sass-rails 6.0.0 Installing sass-rails 6.0.0 Bundle complete! 32 Gemfile dependencies, 98 gems now installed. Gems in the groups 'development' and 'test' were not installed. Bundled gems are installed into `./vendor/bundle` Post-install message from sorcery: As of version 1.0 oauth/oauth2 won't be automatically bundled so you may need to add those dependencies to your Gemfile. You may need oauth2 if you use external providers such as any of these: https://github.com/Sorcery/sorcery/tree/master/lib/sorcery/providers Bundle completed (115.74s) Cleaning up the bundler cache. -----> Installing node-v16.13.1-linux-x64 -----> Installing yarn-v1.22.17 -----> Detecting rake tasks -----> Preparing app for Rails asset pipeline Running: rake assets:precompile Calling `DidYouMean::SPELL_CHECKERS.merge!(error_name => spell_checker)' has been deprecated. Please call `DidYouMean.correct_error(error_name, spell_checker)' instead. yarn install v1.22.17 [1/4] Resolving packages... [2/4] Fetching packages... [3/4] Linking dependencies... warning " > webpack-dev-server@4.10.1" has unmet peer dependency "webpack@^4.37.0 || ^5.0.0". warning "webpack-dev-server > webpack-dev-middleware@5.3.3" has unmet peer dependency "webpack@^4.0.0 || ^5.0.0". [4/4] Building fresh packages... error /tmp/build_fa395875/node_modules/node-sass: Command failed. ① Exit code: 1 Command: node scripts/build.js Arguments: Directory: /tmp/build_fa395875/node_modules/node-sass Output: Building: /tmp/build_fa395875/bin/node /tmp/build_fa395875/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library= gyp info it worked if it ends with ok gyp verb cli [ gyp verb cli '/tmp/build_fa395875/bin/node', gyp verb cli '/tmp/build_fa395875/node_modules/node-gyp/bin/node-gyp.js', gyp verb cli 'rebuild', gyp verb cli '--verbose', gyp verb cli '--libsass_ext=', gyp verb cli '--libsass_cflags=', gyp verb cli '--libsass_ldflags=', gyp verb cli '--libsass_library=' gyp verb cli ] gyp info using node-gyp@3.8.0 gyp info using node@16.13.1 | linux | x64 gyp verb command rebuild [] gyp verb command clean [] gyp verb clean removing "build" directory gyp verb command configure [] gyp verb check python checking for Python executable "python2" in the PATH gyp verb `which` failed Error: not found: python2 gyp verb `which` failed at getNotFoundError (/tmp/build_fa395875/node_modules/which/which.js:13:12) gyp verb `which` failed at F (/tmp/build_fa395875/node_modules/which/which.js:68:19) gyp verb `which` failed at E (/tmp/build_fa395875/node_modules/which/which.js:80:29) gyp verb `which` failed at /tmp/build_fa395875/node_modules/which/which.js:89:16 gyp verb `which` failed at /tmp/build_fa395875/node_modules/isexe/index.js:42:5 gyp verb `which` failed at /tmp/build_fa395875/node_modules/isexe/mode.js:8:5 gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21) gyp verb `which` failed python2 Error: not found: python2 gyp verb `which` failed at getNotFoundError (/tmp/build_fa395875/node_modules/which/which.js:13:12) gyp verb `which` failed at F (/tmp/build_fa395875/node_modules/which/which.js:68:19) gyp verb `which` failed at E (/tmp/build_fa395875/node_modules/which/which.js:80:29) gyp verb `which` failed at /tmp/build_fa395875/node_modules/which/which.js:89:16 gyp verb `which` failed at /tmp/build_fa395875/node_modules/isexe/index.js:42:5 gyp verb `which` failed at /tmp/build_fa395875/node_modules/isexe/mode.js:8:5 gyp verb `which` failed at FSReqCallback.oncomplete (node:fs:198:21) { gyp verb `which` failed code: 'ENOENT' gyp verb `which` failed } gyp verb check python checking for Python executable "python" in the PATH gyp verb `which` succeeded python /usr/bin/python gyp ERR! configure error gyp ERR! stack Error: Command failed: /usr/bin/python -c import sys; print "%s.%s.%s" % sys.version_info[:3]; gyp ERR! stack File "<string>", line 1 gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3]; gyp ERR! stack ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ gyp ERR! stack SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)? gyp ERR! stack gyp ERR! stack at ChildProcess.exithandler (node:child_process:397:12) gyp ERR! stack at ChildProcess.emit (node:events:390:28) gyp ERR! stack at maybeClose (node:internal/child_process:1064:16) gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5) gyp ERR! System Linux 4.4.0-1104-aws gyp ERR! command "/tmp/build_fa395875/bin/node" "/tmp/build_fa395875/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library=" gyp ERR! cwd /tmp/build_fa395875/node_modules/node-sass gyp ERR! node -v v16.13.1 gyp ERR! node-gyp -v v3.8.0 gyp ERR! not ok Build failed with error code: 1 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. ! ! Precompiling assets failed. ! ! Push rejected, failed to compile Ruby app. ! Push failed
ログがすごい長いけど①が怪しい。。。
node-sassのコマンドが失敗したとのことで、これ関係のエラーをググってみると、nodeとnode-sassのバージョンの違いによるものとの事で、以下で解決できました。
①webpackerのバージョンアップ
- gem 'webpacker', '~> 4.0' + gem 'webpacker', '~> 5.0'
②yarn.lockの削除
ファイルを削除する
③package.jsonで以下のようにwebpackerのバージョンを指定
"@rails/webpacker": "5.4.3",
④yarn installを実行
$ yarn install
⑤node-sassのバージョンをnode.jsに合わせる
$ yarn add node-sass
⑥再度デプロイ
$ git push heroku main
※ポイント
・herokuにデプロイするとGemfile.lock
のBUNDLED WITH
が削除されて、heroku指定のBundlerのバージョンが使われる。(自分でbundlerのバージョン指定はできない)
そのため、ローカル環境とheroku環境でbundlerのバージョンが異なるが、bundlerのバージョンの違いによる不具合は、基本的に起こらないとのこと。
・herokuのログは、以下のようにheroku画面でも確認できる
①以下のDashboardをクリック
↓
↓
↓
④以下のLatest activityにログが記載されている
参考記事
RailsをHerokuにデプロイするときのBundlerバージョン(2020年版)|TechRacho by BPS株式会社
【heroku】herokuにてデプロイエラー【The engine "node" is incompatible with this..】