"bundler is upgraded" 和 "error Command "webpack“未找到”时如何部署到 heroku?

How to deploy to heroku when "bundler is upgraded" and "error Command "webpack" not found."?

我最近在名为 alpha-blog 的应用程序中将我的 rails 更新为 v7,我尝试使用 git push heroku main 部署我的应用程序(之前使用的是 v6),然后我遇到了这些

remote: ###### WARNING:
remote: 
remote:        Your app was upgraded to bundler 2.2.33.
remote:        Previously you had a successful deploy with bundler 2.2.21.

error Command "webpack" not found.

我尝试了在 Whosebug 和 github 中找到的几种解决方案(如删除 node_modules、运行、yarn installyarn add webpack 等),但我仍然无法解决部署。谁能帮我解决这个问题?

P/S:我对这些都是新手,所以如果我没有正确表达我的问题,请指正。

您可以在 git push heroku main 之后找到完整的命令:

Enumerating objects: 427, done.
Counting objects: 100% (397/397), done.
Delta compression using up to 12 threads
Compressing objects: 100% (359/359), done.
Writing objects: 100% (361/361), 40.33 KiB | 3.67 MiB/s, done.
Total 361 (delta 203), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/ruby
remote: -----> Ruby app detected
remote: -----> Installing bundler 2.2.33
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: 
remote: ###### WARNING:
remote: 
remote:        Your app was upgraded to bundler 2.2.33.
remote:        Previously you had a successful deploy with bundler 2.2.21.
remote:        
remote:        If you see problems related to the bundler version please refer to:
remote:        https://devcenter.heroku.com/articles/bundler-version#known-upgrade-issues
remote:        
remote: 
remote: -----> Using Ruby version: ruby-3.0.2
remote: -----> Installing dependencies using bundler 2.2.33
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
remote:        Fetching gem metadata from https://rubygems.org/..........
remote:        Using rake 13.0.6
remote:        Using builder 3.2.4
remote:        Using erubi 1.10.0
remote:        Fetching concurrent-ruby 1.1.10
remote:        Fetching minitest 5.15.0
remote:        Using racc 1.6.0
remote:        Using crass 1.0.6
remote:        Using rack 2.2.3
remote:        Using nio4r 2.5.8
remote:        Using websocket-extensions 0.1.5
remote:        Using marcel 1.0.2
remote:        Using mini_mime 1.1.2
remote:        Fetching digest 3.1.0
remote:        Fetching io-wait 0.2.1
remote:        Installing io-wait 0.2.1 with native extensions
remote:        Installing digest 3.1.0 with native extensions
remote:        Installing minitest 5.15.0
remote:        Installing concurrent-ruby 1.1.10
remote:        Fetching timeout 0.2.0
remote:        Installing timeout 0.2.0
remote:        Fetching strscan 3.0.1
remote:        Installing strscan 3.0.1 with native extensions
remote:        Fetching msgpack 1.4.5
remote:        Installing msgpack 1.4.5 with native extensions
remote:        Using bundler 2.2.33
remote:        Fetching ffi 1.15.5
remote:        Installing ffi 1.15.5 with native extensions
remote:        Using method_source 1.0.0
remote:        Fetching pg 1.3.4
remote:        Installing pg 1.3.4 with native extensions
remote:        Fetching thor 1.2.1
remote:        Installing thor 1.2.1
remote:        Fetching zeitwerk 2.5.4
remote:        Installing zeitwerk 2.5.4
remote:        Using tilt 2.0.10
remote:        Using semantic_range 3.0.0
remote:        Using turbolinks-source 5.2.0
remote:        Fetching nokogiri 1.13.3 (x86_64-linux)
remote:        Installing nokogiri 1.13.3 (x86_64-linux)
remote:        Using rack-test 1.1.0
remote:        Using websocket-driver 0.7.5
remote:        Using mail 2.7.1
remote:        Fetching puma 5.6.2
remote:        Installing puma 5.6.2 with native extensions
remote:        Fetching rack-proxy 0.7.2
remote:        Installing rack-proxy 0.7.2
remote:        Fetching i18n 1.10.0
remote:        Installing i18n 1.10.0
remote:        Using tzinfo 2.0.4
remote:        Fetching sprockets 4.0.3
remote:        Installing sprockets 4.0.3
remote:        Fetching net-protocol 0.1.2
remote:        Installing net-protocol 0.1.2
remote:        Using turbolinks 5.2.1
remote:        Fetching bootsnap 1.11.1
remote:        Installing bootsnap 1.11.1 with native extensions
remote:        Fetching loofah 2.15.0
remote:        Installing loofah 2.15.0
remote:        Fetching activesupport 7.0.2.3
remote:        Installing activesupport 7.0.2.3
remote:        Fetching net-imap 0.2.3
remote:        Installing net-imap 0.2.3
remote:        Using net-pop 0.1.1
remote:        Fetching net-smtp 0.3.1
remote:        Installing net-smtp 0.3.1
remote:        Using rails-html-sanitizer 1.4.2
remote:        Using rails-dom-testing 2.0.3
remote:        Fetching globalid 1.0.0
remote:        Installing globalid 1.0.0
remote:        Fetching activemodel 7.0.2.3
remote:        Installing activemodel 7.0.2.3
remote:        Fetching actionview 7.0.2.3
remote:        Installing actionview 7.0.2.3
remote:        Fetching activejob 7.0.2.3
remote:        Installing activejob 7.0.2.3
remote:        Fetching activerecord 7.0.2.3
remote:        Installing activerecord 7.0.2.3
remote:        Fetching actionpack 7.0.2.3
remote:        Installing actionpack 7.0.2.3
remote:        Fetching jbuilder 2.11.5
remote:        Installing jbuilder 2.11.5
remote:        Fetching actioncable 7.0.2.3
remote:        Installing actioncable 7.0.2.3
remote:        Fetching activestorage 7.0.2.3
remote:        Installing activestorage 7.0.2.3
remote:        Fetching actionmailer 7.0.2.3
remote:        Installing actionmailer 7.0.2.3
remote:        Fetching railties 7.0.2.3
remote:        Installing railties 7.0.2.3
remote:        Fetching sprockets-rails 3.4.2
remote:        Installing sprockets-rails 3.4.2
remote:        Fetching actionmailbox 7.0.2.3
remote:        Installing actionmailbox 7.0.2.3
remote:        Fetching actiontext 7.0.2.3
remote:        Installing actiontext 7.0.2.3
remote:        Using webpacker 5.4.3
remote:        Fetching rails 7.0.2.3
remote:        Installing rails 7.0.2.3
remote:        Using sassc 2.4.0
remote:        Using sassc-rails 2.1.2
remote:        Using sass-rails 6.0.0
remote:        Bundle complete! 17 Gemfile dependencies, 64 gems now installed.
remote:        Gems in the groups 'development' and 'test' were not installed.
remote:        Bundled gems are installed into `./vendor/bundle`
remote:        Bundle completed (23.66s)
remote:        Cleaning up the bundler cache.
remote:        Removing actioncable (6.1.4.1)
remote:        Removing actionmailbox (6.1.4.1)
remote:        Removing actionmailer (6.1.4.1)
remote:        Removing actionpack (6.1.4.1)
remote:        Removing actiontext (6.1.4.1)
remote:        Removing actionview (6.1.4.1)
remote:        Removing activejob (6.1.4.1)
remote:        Removing activemodel (6.1.4.1)
remote:        Removing activerecord (6.1.4.1)
remote:        Removing activestorage (6.1.4.1)
remote:        Removing activesupport (6.1.4.1)
remote:        Removing bootsnap (1.9.1)
remote:        Removing concurrent-ruby (1.1.9)
remote:        Removing ffi (1.15.4)
remote:        Removing globalid (0.5.2)
remote:        Removing i18n (1.8.11)
remote:        Removing jbuilder (2.11.3)
remote:        Removing loofah (2.12.0)
remote:        Removing minitest (5.14.4)
remote:        Removing msgpack (1.4.2)
remote:        Removing nokogiri-1.12.5-x86_64 (linux)
remote:        Removing pg (1.2.3)
remote:        Removing puma (5.5.2)
remote:        Removing rack-proxy (0.7.0)
remote:        Removing rails (6.1.4.1)
remote:        Removing railties (6.1.4.1)
remote:        Removing sprockets (4.0.2)
remote:        Removing sprockets-rails (3.4.0)
remote:        Removing thor (1.1.0)
remote:        Removing zeitwerk (2.5.1)
remote: -----> Installing node-v16.13.1-linux-x64
remote: -----> Installing yarn-v1.22.17
remote: -----> Detecting rake tasks
remote: -----> Preparing app for Rails asset pipeline
remote:        Running: rake assets:precompile
remote:        I, [2022-03-29T08:24:04.218234 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/actiontext-28c61f5197c204db043317a8f8826a87ab31495b741f854d307ca36122deefce.js
remote:        I, [2022-03-29T08:24:04.218394 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/actiontext-28c61f5197c204db043317a8f8826a87ab31495b741f854d307ca36122deefce.js.gz
remote:        I, [2022-03-29T08:24:04.218753 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/trix-1563ff9c10f74e143b3ded40a8458497eaf2f87a648a5cbbfebdb7dec3447a5e.js
remote:        I, [2022-03-29T08:24:04.218907 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/trix-1563ff9c10f74e143b3ded40a8458497eaf2f87a648a5cbbfebdb7dec3447a5e.js.gz
remote:        I, [2022-03-29T08:24:04.219248 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/trix-6fd35bb8fae1d6a795115763ca265369b9750f73a1c6283a0b0ef4b6c2d550c8.css
remote:        I, [2022-03-29T08:24:04.219337 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/trix-6fd35bb8fae1d6a795115763ca265369b9750f73a1c6283a0b0ef4b6c2d550c8.css.gz
remote:        I, [2022-03-29T08:24:04.219457 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/activestorage-3ab61e47dd4ee2d79db525ade1dca2ede0ea2b7371fe587e408ee37b7ade265d.js
remote:        I, [2022-03-29T08:24:04.219545 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/activestorage-3ab61e47dd4ee2d79db525ade1dca2ede0ea2b7371fe587e408ee37b7ade265d.js.gz
remote:        I, [2022-03-29T08:24:04.219684 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/activestorage.esm-01f58a45d77495cdfbdfcc872902a430426c4391634ec9c3da5f69fbf8418492.js
remote:        I, [2022-03-29T08:24:04.219806 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/activestorage.esm-01f58a45d77495cdfbdfcc872902a430426c4391634ec9c3da5f69fbf8418492.js.gz
remote:        I, [2022-03-29T08:24:04.220170 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/actioncable-da745289dc396d1588ddfd149d68bb8e519d9e7059903aa2bb98cfc57be6d66e.js
remote:        I, [2022-03-29T08:24:04.220262 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/actioncable-da745289dc396d1588ddfd149d68bb8e519d9e7059903aa2bb98cfc57be6d66e.js.gz
remote:        I, [2022-03-29T08:24:04.220373 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/actioncable.esm-3d92de0486af7257cac807acf379cea45baf450c201e71e3e84884c0e1b5ee15.js
remote:        I, [2022-03-29T08:24:04.220451 #1093]  INFO -- : Writing /tmp/build_86463fbd/public/assets/actioncable.esm-3d92de0486af7257cac807acf379cea45baf450c201e71e3e84884c0e1b5ee15.js.gz
remote:        Compiling...
remote:        Compilation failed:
remote:        yarn run v1.22.17
remote:        info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
remote:        
remote:        
remote:        error Command "webpack" not found.
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 reject

解决问题并成功部署应用程序的答案

尝试在 Heroku nodejs 构建包中添加:

heroku buildpacks:add --index 1 heroku/nodejs -a your-app-name