我正在尝试在 CML 中运行 heroku 本地命令
heroku local
。 heroku local
命令允许您在本地启动项目,就像将项目推送到 Heroku 一样,以解决本地开发环境中的问题。我尝试删除 Gemfile.lock 并再次运行捆绑安装,但没有成功。我也尝试使用命令 bundle exec heroku local
但仍然收到相同的错误消息。
我通过 CML 使用 home-brew 安装了 ruby。
ruby-v
的输出:ruby 2.7.6p219 (2022-04-12 revision c9c2245c0a) [arm64-darwin21]
。 file $(which ruby)
的输出:Users/chris/.rubies/ruby-2.7.6/bin/ruby: Mach-O 64-bit executable arm64.
我的宝石文件:
source "https://rubygems.org"
ruby "2.7.6"
gem "sinatra", "~>1.4.7"
gem "sinatra-contrib"
gem "erubis"
group :production do
gem "puma"
end
我的 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
预期回报值:
$ 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
实际返回值:
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
我尝试删除 Gemfile.lock 并再次运行捆绑安装,但没有成功。我也尝试使用命令
bundle exec heroku local
但仍然收到相同的错误消息。
当您的应用程序在 Apple Silicon 上本地运行并在 Heroku 上生产时,这意味着您正在不同的平台上运行您的应用程序。而且您必须让 Bundler 意识到它需要能够处理两个平台所需的 gem。
虽然 Bundler 的通用
ruby
平台在大多数情况下都可以工作,但在某些边缘情况下,需要或首选使用特定于平台的版本。例如,如果不使用正确的平台,在 Apple Silicon 上安装 libv8-node
gem 的速度非常慢。另一个例子似乎是您正在使用的 puma
gem,它明确要求 正确的平台配置才能工作。
因此,我建议将您当前使用的所有平台添加到
Gemfile
。这可以确保您不会添加不适用于所有平台的 gem。使用平台优化版本的能力应该会提高尤其是具有 C 绑定的 gem 的编译时间。
我建议将您正在使用的所有平台(根据错误消息)添加到您的 Gemfile 中,如下所示:
bundle lock --add-platform ruby x86_64 arm64
然后再次运行
bundle install
。
bundle platform
和 bundle lock
的 Bundler 文档。
我想通了!所以问题是我使用的是x86_64架构,但我需要使用arm64架构。我使用命令
uname -m
验证了哪种架构。要切换到arm64,我使用了命令env /usr/bin/arch -arm64 /bin/zsh --login
。