首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“.bin/bundle:第11行:要求:未找到命令.bin/bundle.未能通过Bundler.‘安装gems。

“.bin/bundle:第11行:要求:未找到命令.bin/bundle.未能通过Bundler.‘安装gems。
EN

Stack Overflow用户
提问于 2021-10-27 03:01:05
回答 1查看 134关注 0票数 0

我试图将我的Rails api专用应用程序部署到Heroku,当我运行git push heroku main时,我得到了以下错误:

代码语言:javascript
复制
Counting objects: 100% (1198/1198), done.
Delta compression using up to 8 threads
Compressing objects: 100% (417/417), done.
Writing objects: 100% (1198/1198), 171.98 KiB | 21.50 MiB/s, done.
Total 1198 (delta 715), reused 1188 (delta 711), pack-reused 0
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpacks:
remote:        1. heroku/ruby
remote:        2. https://github.com/heroku/heroku-buildpack-ruby.git
remote: -----> Ruby app detected
remote: -----> Installing bundler 2.2.21
remote: -----> Removing BUNDLED WITH version in the Gemfile.lock
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-3.0.2
remote: -----> Installing dependencies using bundler 2.2.21
remote:        Running: BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4
remote:        /tmp/build_814ed8d0/bin/bundle: line 11: require: command not found
remote:        /tmp/build_814ed8d0/bin/bundle: line 13: m: command not found
remote:        /tmp/build_814ed8d0/bin/bundle: line 14: module_function: command not found
remote:        /tmp/build_814ed8d0/bin/bundle: line 16: def: command not found
remote:        /tmp/build_814ed8d0/bin/bundle: line 17: syntax error near unexpected token `$PROGRAM_NAME'
remote:        /tmp/build_814ed8d0/bin/bundle: line 17: `    File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)'
remote:        Bundler Output: /tmp/build_814ed8d0/bin/bundle: line 11: require: command not found
remote:        /tmp/build_814ed8d0/bin/bundle: line 13: m: command not found
remote:        /tmp/build_814ed8d0/bin/bundle: line 14: module_function: command not found
remote:        /tmp/build_814ed8d0/bin/bundle: line 16: def: command not found
remote:        /tmp/build_814ed8d0/bin/bundle: line 17: syntax error near unexpected token `$PROGRAM_NAME'
remote:        /tmp/build_814ed8d0/bin/bundle: line 17: `    File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)'
remote: 
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote: 
remote:  !     Push failed
remote: Verifying deploy...
remote: 
remote: !       Push rejected to murmuring-forest-17162.
remote: 
To https://git.heroku.com/murmuring-forest-17162.git
 ! [remote rejected] main -> main (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/murmuring-forest-17162.git'

我的本地文件看起来像那个bin/bundle

代码语言:javascript
复制
# frozen_string_literal: true

#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

m = Module.new do
  module_function

  def invoked_as_script?
    File.expand_path($PROGRAM_NAME) == File.expand_path(__FILE__)
  end

  def env_var_version
    ENV['BUNDLER_VERSION']
  end

  def cli_arg_version # rubocop:disable Metrics/PerceivedComplexity, Metrics/MethodLength, Metrics/CyclomaticComplexity
    return unless invoked_as_script? # don't want to hijack other binstubs
    return unless 'update'.start_with?(ARGV.first || ' ') # must be running `bundle update`

    bundler_version = nil
    update_index = nil
    ARGV.each_with_index do |a, i|
      bundler_version = a if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
      next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/

      bundler_version = Regexp.last_match(1)
      update_index = i
    end
    bundler_version
  end

  def gemfile
    gemfile = ENV['BUNDLE_GEMFILE']
    return gemfile if gemfile && !gemfile.empty?

    File.expand_path('../Gemfile', __dir__)
  end

  def lockfile
    lockfile =
      case File.basename(gemfile)
      when 'gems.rb' then gemfile.sub(/\.rb$/, gemfile)
      else "#{gemfile}.lock"
      end
    File.expand_path(lockfile)
  end

  def lockfile_version
    return unless File.file?(lockfile)

    lockfile_contents = File.read(lockfile)
    return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/

    Regexp.last_match(1)
  end

  def bundler_version
    @bundler_version ||=
      env_var_version || cli_arg_version ||
      lockfile_version
  end

  def bundler_requirement
    return "#{Gem::Requirement.default}.a" unless bundler_version

    bundler_gem_version = Gem::Version.new(bundler_version)

    requirement = bundler_gem_version.approximate_recommendation

    return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new('2.7.0')

    requirement += '.a' if bundler_gem_version.prerelease?

    requirement
  end

  def load_bundler!
    ENV['BUNDLE_GEMFILE'] ||= gemfile

    activate_bundler
  end

  def activate_bundler # rubocop:disable Metrics/MethodLength
    gem_error = activation_error_handling do
      gem 'bundler', bundler_requirement
    end
    return if gem_error.nil?

    require_error = activation_error_handling do
      require 'bundler/version'
    end
    if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
      return
    end

    warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`" # rubocop:disable Layout/LineLength
    exit 42
  end

  def activation_error_handling
    yield
    nil
  rescue StandardError, LoadError => e
    e
  end
end

m.load_bundler!

load Gem.bin_path('bundler', 'bundle') if m.invoked_as_script?

我试图将我的红宝石版本和平装版本更改为Heroku使用的相同版本,但结果并没有改变:

代码语言:javascript
复制
bundler -v
Bundler version 2.2.21

ruby -v
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin20]

rbenv -v
rbenv 1.1.2

我的Gemfile

代码语言:javascript
复制
# frozen_string_literal: true

source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '3.0.2'

gem 'bootsnap', '>= 1.4.4', require: false
gem 'bcrypt'
gem 'dry-monads'
gem 'grape-swagger'
gem 'grape-swagger-entity'
gem 'jwt'
gem 'net-http'
gem 'pg', '~> 1.1'
gem 'puma', '~> 5.0'
gem 'pundit'
gem 'rack-cors'
gem 'ransack', github: 'activerecord-hackery/ransack'
gem 'rails', '~> 6.1.4.1'
gem 'redis'
gem 'require_all'
gem 'strong_migrations'
gem 'uri'

group :development do
  gem 'database_consistency', require: false
  gem 'listen', '~> 3.3'
  gem 'rubocop', require: false
  gem 'rubocop-discourse', require: false
  gem 'rubocop-rails', require: false
  gem 'spring'
end

group :development, :test do
  gem 'bullet'
  gem 'bundler-audit'
  gem 'byebug', platforms: %i[mri mingw x64_mingw]
  gem 'dotenv-rails'
  gem 'factory_bot_rails'
  gem 'ffaker'
  gem 'rspec-rails', '~> 5.0.0'
end

group :test do
  gem 'rspec-sqlimit'
  gem 'shoulda-matchers', '~> 5.0'
  gem 'webmock'
end

gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]

在我的Gemfile.lock的结尾

代码语言:javascript
复制
...


RUBY VERSION
   ruby 3.0.2p107

BUNDLED WITH
   2.2.21

我尝试过(如您在heroku日志中所看到的)连接不同的ruby,但没有帮助。

我试图删除Gemfile.lock,重新安装gems并将更新的文件推回主分支,但没有帮助。

我尝试用与Heroku使用(BUNDLE_WITHOUT='development:test' BUNDLE_PATH=vendor/bundle BUNDLE_BIN=vendor/bundle/bin BUNDLE_DEPLOYMENT=1 bundle install -j4)相同的命令在本地安装gems,并将其推到git vendor/bundle文件夹,但没有帮助。

我试着按照日志的建议运行git push heroku main:main,但是没有帮助。

每次我看到同样的错误。

任何人都有想法,我做错了什么,怎么解决呢?提前谢谢你!

EN

回答 1

Stack Overflow用户

发布于 2021-10-28 08:33:37

原因是在文件bin/bundle中。因为这是可执行的shell文件,所以这里的第一行必须是#!/usr/bin/env ruby。当我删除前几行多余的几行时,Heroku像我所期望的那样读取ruby文件。

这是bin/bundle的工作版本。

代码语言:javascript
复制
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69732241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档