Home > other >  bundler: failed to load command: puma
bundler: failed to load command: puma

Time:12-14

Im trying to run the heroku local command in CML heroku local. heroku local command allows you to boot the project locally in the same way that it will be once it's pushed to Heroku to troubleshoot problems in a local development environment. Ive tried deleting my Gemfile.lock and running bundle install again did not work. I also tried using command bundle exec heroku local and I'm still getting the same error message.

I installed ruby using home-brew through the CML. Output of ruby-v: ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [arm64-darwin21]. Output of file $(which ruby): Users/chris/.rubies/ruby-2.7.6/bin/ruby: Mach-O 64-bit executable arm64.

My GemFile:

source "https://rubygems.org"

ruby "2.7.6"
gem "sinatra", "~>1.4.7"
gem "sinatra-contrib"
gem "erubis"

group :production do
  gem "puma"
end

My Gemfile.lock:

GEM
  remote: https://rubygems.org/
  specs:
    backports (3.23.0)
    erubis (2.7.0)
    multi_json (1.15.0)
    nio4r (2.5.8)
    puma (6.0.0)
      nio4r (~> 2.0)
    rack (1.6.13)
    rack-protection (1.5.5)
      rack
    rack-test (2.0.2)
      rack (>= 1.3)
    sinatra (1.4.8)
      rack (~> 1.5)
      rack-protection (~> 1.4)
      tilt (>= 1.3, < 3)
    sinatra-contrib (1.4.7)
      backports (>= 2.0)
      multi_json
      rack-protection
      rack-test
      sinatra (~> 1.4.0)
      tilt (>= 1.3, < 3)
    tilt (2.0.11)

PLATFORMS
  arm64-darwin-21

DEPENDENCIES
  erubis
  puma
  sinatra (~> 1.4.7)
  sinatra-contrib

RUBY VERSION
   ruby 2.7.6p219

BUNDLED WITH
   2.3.26

Expected return value:

$ heroku local
forego | starting web.1 on port 5000
web.1  | Puma starting in single mode...
web.1  | * Listening on tcp://0.0.0.0:5000
web.1  | Use Ctrl-C to stop

Actual return value:

bundler: failed to load command: puma (/Users/chris/.gem/ruby/2.7.6/bin/puma)
4:29:41 PM web.1 |  /Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0/lib/puma.rb:14:in `require': dlopen(/Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0/lib/puma/puma_http11.bundle, 0x0009): tried: '/Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0/lib/puma/puma_http11.bundle' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0/lib/puma/puma_http11.bundle' (no such file), '/Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0
4:29:41 PM web.1 |  >  /lib/puma/puma_http11.bundle' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')) - /Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0/lib/puma/puma_http11.bundle (LoadError)
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0/lib/puma.rb:14:in `<top (required)>'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0/lib/puma/cli.rb:6:in `require_relative'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0/lib/puma/cli.rb:6:in `<top (required)>'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0/bin/puma:6:in `require'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/puma-6.0.0/bin/puma:6:in `<top (required)>'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/bin/puma:25:in `load'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/bin/puma:25:in `<top (required)>'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/cli/exec.rb:58:in `load'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/cli/exec.rb:58:in `kernel_load'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/cli/exec.rb:23:in `run'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/cli.rb:486:in `exec'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor.rb:392:in `dispatch'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/cli.rb:31:in `dispatch'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/vendor/thor/lib/thor/base.rb:485:in `start'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/cli.rb:25:in `start'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/exe/bundle:48:in `block in <top (required)>'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/lib/bundler/friendly_errors.rb:120:in `with_friendly_errors'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/gems/bundler-2.3.26/exe/bundle:36:in `<top (required)>'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/bin/bundle:25:in `load'
4:29:41 PM web.1 |      from /Users/chris/.gem/ruby/2.7.6/bin/bundle:25:in `<main>'
[DONE] Killing all processes with signal  SIGINT
4:29:41 PM web.1 Exited with exit code null

Ive tried deleting my Gemfile.lock and running bundle install again did not work. I also tried using command bundle exec heroku local and I'm still getting the same error message.

CodePudding user response:

When running your application locally on Apple Silicon and on production on Heroku then that means you are running your application on different platforms. And you have to make Bundler aware that it needs to be able to handle the required gems for all platforms.

While Bundler's generic ruby platform works in most cases, there are edge cases in which working with the platform-specific versions is required or preferred. For example, installing the libv8-node gem is extremely slow in Apple Silicon when not using the correct platform. Another example seems to be the puma gem you are using that explicitly requires the correct platform configuration to work.

Therefore, I suggest adding all platforms that you are currently using to the Gemfile. That ensures that you do not add gems that are not available for all platforms. And the ability to use platform-optimized versions should improve especially the compiling time of gems with C bindings.

I suggest adding all platforms you are using (according to the error message) to your Gemfile like this:

bundle lock --add-platform ruby x86_64 arm64

Then run bundle install again.

See the Bundler documentation about bundle platform and bundle lock.

CodePudding user response:

The issue is that the puma gem is compiled for the x86_64 architecture, but your Ruby installation is for the arm64 architecture. This means that the puma gem cannot be loaded by your Ruby installation because it is not compatible with your system.

To fix this issue, you need to recompile the puma gem for the arm64 architecture. You can do this by running the following commands:

1.Install the puma gem from source: gem install puma --source https://rubygems.org --build-flags="-O3 -march=native -mtune=native"

2.Rebuild the Gemfile.lock file to include the newly installed puma gem: bundle install

3.Run the heroku local command again: heroku local

This should fix the issue and allow the puma gem to be loaded correctly by your Ruby installation.

  • Related