【问题标题】:Cannot deploy rails app to Heroku无法将 Rails 应用程序部署到 Heroku
【发布时间】:2018-05-13 19:18:24
【问题描述】:

我正在尝试将我的 rails 应用程序部署到 heroku,但由于不断出现错误 当我执行“git push heroku master”时,我一直无法做到。错误是这样出现的:

$ git push heroku master
Counting objects: 8942, done.

Delta compression using up to 4 threads.
Compressing objects: 100% (8320/8320), done.
Writing objects: 100% (8942/8942), 38.02 MiB | 1.59 MiB/s, done.
Total 8942 (delta 1019), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote:  !     Warning: Multiple default buildpacks reported the abi
lity to handle this app. The first buildpack in the list below will
be used.
remote:                         Detected buildpacks: Ruby,Node.js
remote:                         See https://devcenter.heroku.com/art
icles/buildpacks#buildpack-detect-order
remote: -----> Ruby app detected
remote: -----> Compiling Ruby/Rails
remote: -----> Using Ruby version: ruby-2.3.7
remote: -----> Installing dependencies using bundler 1.15.2
remote:        Running: bundle install --without development:test --
path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
remote:        Warning: the running version of Bundler (1.15.2) is o
lder than the version that created the lockfile (1.16.1). We suggest
 you upgrade to the latest version of Bundler by running `gem instal
l bundler`.
remote:        Fetching gem metadata from https://rubygems.org/.....
...
remote:        Fetching version metadata from https://rubygems.org/.
.
remote:        Fetching dependency metadata from https://rubygems.or
g/.
remote:        Fetching rake 12.3.1
remote:        Fetching concurrent-ruby 1.0.5
remote:        Fetching minitest 5.11.3
remote:        Installing rake 12.3.1
(...)
remote:        Installing activesupport 5.1.6
remote:        Gem::Ext::BuildError: ERROR: Failed to build gem nati
ve extension.
remote:
remote:        current directory:
remote:        /tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/vendor/bu
ndle/ruby/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
remote:        /tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/vendor/ru
by-2.3.7/bin/ruby -r
remote:        ./siteconf20180513-253-1utdlov.rb extconf.rb
remote:        checking for sqlite3.h... no
remote:        sqlite3.h is missing. Try 'brew install sqlite3',
remote:        'yum install sqlite-devel' or 'apt-get install libsql
ite3-dev'
remote:        and check your shared library search path (the
remote:        location where your sqlite3 shared library is located
).
remote:        *** extconf.rb failed ***
remote:        Could not create Makefile due to some reason, probabl
y lack of necessary
remote:        libraries and/or headers.  Check the mkmf.log file fo
r more details.  You may
remote:        need configuration options.
remote:
remote:        Provided configuration options:
remote:         --with-opt-dir
remote:         --without-opt-dir
remote:         --with-opt-include
remote:         --without-opt-include=${opt-dir}/include
remote:         --with-opt-lib
remote:         --without-opt-lib=${opt-dir}/lib
remote:         --with-make-prog
remote:         --srcdir=.

remote:         --curdir
remote:        --ruby=/tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/ve
ndor/ruby-2.3.7/bin/$(RUBY_BASE_NAME)
remote:         --with-sqlite3-config
remote:         --without-sqlite3-config
remote:         --with-pkg-config
remote:         --without-pkg-config
remote:         --with-sqlite3-dir
remote:         --without-sqlite3-dir
remote:         --with-sqlite3-include
remote:         --without-sqlite3-include=${sqlite3-dir}/include
remote:         --with-sqlite3-lib
remote:         --without-sqlite3-lib=${sqlite3-dir}/lib
remote:
remote:        To see why this extension failed to compile, please c
heck the mkmf.log which can
remote:        be found here:
remote:
remote:        /tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/vendor/bu
ndle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/mkmf.lo
g
remote:
remote:        extconf failed, exit code 1
remote:
remote:        Gem files will remain installed in
remote:        /tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/vendor/bu
ndle/ruby/2.3.0/gems/sqlite3-1.3.13
remote:        for inspection.
remote:        Results logged to
remote:        /tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/vendor/bu
ndle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_mak
e.out
remote:
remote:        An error occurred while installing sqlite3 (1.3.13),
and Bundler cannot
remote:        continue.
remote:        Make sure that `gem install sqlite3 -v '1.3.13'` succ
eeds before bundling.
remote:
remote:        In Gemfile:
remote:          sqlite3
remote:        Bundler Output: Warning: the running version of Bundl
er (1.15.2) is older than the version that created the lockfile (1.1
6.1). We suggest you upgrade to the latest version of Bundler by run
ning `gem install bundler`.
remote:        Fetching gem metadata from https://rubygems.org/.....
...
remote:        Fetching version metadata from https://rubygems.org/.
.
remote:        Fetching dependency metadata from https://rubygems.or
g/.
remote:        Fetching rake 12.3.1
remote:        Fetching concurrent-ruby 1.0.5
(...)
remote:        Installing activesupport 5.1.6
remote:        Gem::Ext::BuildError: ERROR: Failed to build gem nati
ve extension.
remote:
remote:        current directory:
remote:        /tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/vendor/bu
ndle/ruby/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
remote:        /tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/vendor/ru
by-2.3.7/bin/ruby -r
remote:        ./siteconf20180513-253-1utdlov.rb extconf.rb
remote:        checking for sqlite3.h... no
remote:        sqlite3.h is missing. Try 'brew install sqlite3',
remote:        'yum install sqlite-devel' or 'apt-get install libsql
ite3-dev'
remote:        and check your shared library search path (the
remote:        location where your sqlite3 shared library is located
).
remote:        *** extconf.rb failed ***
remote:        Could not create Makefile due to some reason, probabl
y lack of necessary
remote:        libraries and/or headers.  Check the mkmf.log file fo
r more details.  You may
remote:        need configuration options.
remote:
remote:        Provided configuration options:
remote:         --with-opt-dir
remote:         --without-opt-dir
remote:         --with-opt-include
remote:         --without-opt-include=${opt-dir}/include
remote:         --with-opt-lib
remote:         --without-opt-lib=${opt-dir}/lib
remote:         --with-make-prog
remote:         --without-make-prog
remote:         --srcdir=.
remote:         --curdir
remote:        --ruby=/tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/ve
ndor/ruby-2.3.7/bin/$(RUBY_BASE_NAME)
remote:         --with-sqlite3-config
remote:         --without-sqlite3-config
remote:         --with-pkg-config
remote:         --without-pkg-config
remote:         --with-sqlite3-dir
remote:         --without-sqlite3-dir
remote:         --with-sqlite3-include
remote:         --without-sqlite3-include=${sqlite3-dir}/include
remote:         --with-sqlite3-lib
remote:         --without-sqlite3-lib=${sqlite3-dir}/lib
remote:
remote:        To see why this extension failed to compile, please c
heck the mkmf.log which can
remote:        be found here:
remote:
remote:        /tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/vendor/bu
ndle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/mkmf.lo
g
remote:
remote:        extconf failed, exit code 1
remote:
remote:        Gem files will remain installed in
remote:        /tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/vendor/bu
ndle/ruby/2.3.0/gems/sqlite3-1.3.13
remote:        for inspection.
remote:        Results logged to
remote:        /tmp/build_cffd92476daf50cbcc0ddddd7e5ac406/vendor/bu
ndle/ruby/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_mak
e.out
remote:
remote:        An error occurred while installing sqlite3 (1.3.13),
and Bundler cannot
remote:        continue.
remote:        Make sure that `gem install sqlite3 -v '1.3.13'` succ
eeds before bundling.
remote:
remote:        In Gemfile:
remote:          sqlite3
remote:  !
remote:  !     Failed to install gems via Bundler.
remote:  !     Detected sqlite3 gem which is not supported on Heroku
:
remote:  !     https://devcenter.heroku.com/articles/sqlite3
remote:  !
remote:  !     Push rejected, failed to compile Ruby app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to XXXXX.
remote:
To https://git.heroku.com/XXXXX.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/XXXXX.git'

我的 Gemfile 在 [更新] 以下:

source 'https://rubygems.org'

git_source(:github) do |repo_name|
  repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
  "https://github.com/#{repo_name}.git"
end


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.6'

group :production do
  gem 'pg'
end

# Use Puma as the app server
gem 'puma', '~> 3.7'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.2'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 4.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'

# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
  # Adds support for Capybara system testing and selenium driver
  gem 'capybara', '~> 2.13'
  gem 'selenium-webdriver'

  gem 'pry-rails'  
  gem 'pry-doc'    
  gem 'pry-byebug' 
  gem 'pry-stack_explorer' 
  gem 'hirb'         
  gem 'hirb-unicode' 
  gem 'better_errors'
  gem "binding_of_caller"

  # Use sqlite3 as the database for Active Record
  gem 'sqlite3', require: false
end

group :development do
  # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
  gem 'web-console', '>= 3.3.0'
  gem 'listen', '>= 3.0.5', '< 3.2'
  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'
  gem 'spring-watcher-listen', '~> 2.0.0'
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem 'devise'

gem 'omniauth-facebook'

gem 'dotenv-rails', require: 'dotenv/rails-now'

gem 'thin'

gem 'carrierwave'

gem 'rails-erd'

gem 'jquery-rails'

我是 ruby​​-on-rails 的初学者开发人员,完全不知道如何解决这个问题。非常感谢任何帮助!

【问题讨论】:

    标签: ruby-on-rails postgresql heroku sqlite


    【解决方案1】:

    首先,确保您拥有正确的 gemfile,它应该是这样的:

    group :production do  
      gem 'pg'
    end
    

    运行

    bundle install

    编辑config/database.yml

    development:
     adapter: sqlite3
     database: db/development.sqlite3
     pool: 5
     timeout: 5000
    
    test:
      adapter: sqlite3
      database: db/test.sqlite3
      pool: 5
      timeout: 5000
    
    production:
      adapter: postgresql
      database: my_database_production
      pool: 5
      timeout: 5000
    

    最后提交更改

    git commit -am 'changes'

    将更改上传到heroku

    git push heroku master

    确保在 heroku 中创建 bd

    heroku addons:create heroku-postgresql
    

    这篇文章可以帮到你https://devcenter.heroku.com/articles/sqlite3

    【讨论】:

    • 您好,感谢您的支持!我已经按照您的建议在 group :production 中插入了“gem 'pg'”,并再次进行了git push heroku master,情况保持不变。错误信息完全相同。
    • 我已按照您的指示进行操作,但不幸的是情况相同...错误消息仍然指示checking for sqlite3.h... no。我也按照下面的说明进行操作,但结果是一样的……stackoverflow.com/questions/41370565/…
    • 在开发中你可以使用另一个 bd,比如 pg 或 mysql 吗?
    【解决方案2】:

    记录在 Heroku 的网站上。 (https://devcenter.heroku.com/articles/sqlite3#getting-a-sqlite-error-even-though-it-is-not-in-the-gemfile)。您的 database.yml 应如下所示:

    development:
     adapter: postgresql
     database: my_database_development
     pool: 5
     timeout: 5000
    
    test:
     adapter: postgresql
     database: my_database_test
     pool: 5
     timeout: 5000
    
    production:
     adapter: postgresql
     database: my_database_production
     pool: 5
     timeout: 5000
    

    进行这些更改后,请确保运行以下命令:

    rake db:create
    rake db:migrate
    

    现在您需要git addgit commit -m postgres。如果您在尝试所有这些步骤后仍然遇到错误,您可能不得不亲自动手并进行一些调查,因为您的 gemfile 中的其中一个 gem 很可能使用 SQL 作为依赖项。从查看您的 Gemfile.lock 开始。请看下面:

    得到一个 SQLite 错误,即使它不在 Gemfile 中: 如果您从 Gemfile 中删除了 gem 'sqlite3' 行,并且在部署到 Heroku 时仍然出现错误,则很可能您正在使用的另一个 gem 具有 sqlite3 作为依赖项。为了帮助找到这种依赖的来源,请查看您的 Gemfile.lock for sqlite3。找到将 sqlite3 作为依赖项的 gem,并将其从 Gemfile 中删除。一旦你完成了这个运行 bundle install 并确保你的 Gemfile.lock 中不再存在 sqlite3。

    希望对您有所帮助。

    【讨论】:

    • 感谢您的帮助。我输入了gem dependency sqlite3,发现下面的gem 依赖于它:hoe (~&gt; 3.15, development) hoe-bundler (~&gt; 1.0, development) mini_portile (~&gt; 0.6.2, development) minitest (~&gt; 5.9, development) rake-compiler (~&gt; 0.9.3, development) rake-compiler-dock (~&gt; 0.5.2, development) rdoc (~&gt; 4.0, development) 但问题是即使我尝试执行gem uninstall xxx(e.g. hoe),它也会显示“未安装Gem 'hoe'。”我该怎么办?
    • 该命令仅列出 gem 的依赖项实际上是什么。这并不意味着它们已集成到您的项目中。您必须转到 Gemfile.lock 并查看这些依赖项,看看是否可以找到任何可能需要 sqlite3 作为依赖项的 gem。你怀疑的任何 gem,去 github repo 并检查它们的依赖项(即:gemfile),看看 sqlite3 是否是一个。
    【解决方案3】:

    哦,终于发现问题已经解决了! 我在我的 git 的一个开发分支中,当我将它合并到 master 并执行git push heroku master 时,它进展顺利。直到我阅读下面的内容,我才意识到问题是由一个简单的因素引起的。 非常感谢您的帮助!

    参考Heroku installing sqlite3 even though it is not a dependecy

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-16
      • 1970-01-01
      • 2015-12-25
      • 1970-01-01
      • 1970-01-01
      • 2015-10-25
      相关资源
      最近更新 更多