When pushing to Heroku: An error occurred in the a

2019-09-02 07:57发布

问题:

I've been stuck on this for a few hours and can't seem to get it working.

I am following a tutorial and I'm trying to push my app to Heroku.

My gemfile looks like:

source 'https://rubygems.org'
ruby '2.0.0'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.1'


# Gems used only for assets and not required 
# in production environments by default. 
group :assets do 
# Use SCSS for stylesheets
 gem 'sass-rails', '~> 4.0.3'
 gem 'coffee-rails'
 gem 'uglifier', '1.2.3' 
end 

# Use jquery as the JavaScript library
gem 'jquery-rails'

group :development, :test do 
 gem 'sqlite3'
 gem 'rspec-rails', '2.10.0' 
end 

group :production do 
 gem 'pg'
end 

When I push to Heroku, I get this:

    Lisa:sample_app admin-lisa$ git push heroku master
Initializing repository, done.
Counting objects: 81, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (68/68), done.
Writing objects: 100% (81/81), 17.36 KiB, done.
Total 81 (delta 12), reused 0 (delta 0)

-----> Ruby app detected
-----> Compiling Ruby/Rails
-----> Using Ruby version: ruby-2.0.0
-----> Installing dependencies using 1.6.3
       Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
       Fetching gem metadata from https://rubygems.org/..........
       Fetching additional metadata from https://rubygems.org/..
       Installing i18n 0.6.9
       Installing rake 10.3.2
       Installing minitest 5.3.5
       Installing thread_safe 0.3.4
       Installing builder 3.2.2
       Installing rack 1.5.2
       Installing erubis 2.7.0
       Installing polyglot 0.3.5
       Installing mime-types 1.25.1
       Installing coffee-script-source 1.7.0
       Installing arel 5.0.1.20140414130214
       Installing execjs 2.2.1
       Installing hike 1.2.3
       Installing thor 0.19.1
       Installing multi_json 1.10.1
       Using bundler 1.6.3
       Installing json 1.8.1
       Installing tilt 1.4.1
       Installing tzinfo 1.2.1
       Installing sass 3.2.19
       Installing rack-test 0.6.2
       Installing coffee-script 2.2.0
       Installing treetop 1.4.15
       Installing uglifier 1.2.3
       Installing sprockets 2.11.0
       Installing activesupport 4.1.1
       Installing mail 2.5.4
       Installing actionview 4.1.1
       Installing activemodel 4.1.1
       Installing actionpack 4.1.1
       Installing activerecord 4.1.1
       Installing actionmailer 4.1.1
       Installing sprockets-rails 2.1.3
       Installing railties 4.1.1
       Installing jquery-rails 3.1.1
       Installing coffee-rails 4.0.1
       Installing sass-rails 4.0.3
       Installing rails 4.1.1
       Installing pg 0.17.1
       Your bundle is complete!
       Gems in the groups development and test were not installed.
       It was installed into ./vendor/bundle
       Bundle completed (27.18s)
       Cleaning up the bundler cache.
-----> Preparing app for Rails asset pipeline
       Running: rake assets:precompile
       rake aborted!
       Sprockets::FileNotFound: couldn't find file 'turbolinks'
       (in /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/app/assets/javascripts/application.js:15)
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/context.rb:106:in `resolve'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/context.rb:146:in `require_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/directive_processor.rb:217:in `process_require_directive'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/directive_processor.rb:167:in `block in process_directives'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/directive_processor.rb:165:in `each'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/directive_processor.rb:165:in `process_directives'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/directive_processor.rb:99:in `evaluate'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/context.rb:197:in `block in evaluate'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/context.rb:194:in `each'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/context.rb:194:in `evaluate'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/processed_asset.rb:12:in `initialize'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:374:in `new'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:374:in `block in build_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:395:in `circular_call_protection'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:373:in `build_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/index.rb:94:in `block in build_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/caching.rb:58:in `cache_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/index.rb:93:in `build_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:287:in `find_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/index.rb:61:in `find_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/bundled_asset.rb:16:in `initialize'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:377:in `new'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:377:in `build_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/index.rb:94:in `block in build_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/caching.rb:58:in `cache_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/index.rb:93:in `build_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/base.rb:287:in `find_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/index.rb:61:in `find_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:211:in `block in find_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:257:in `benchmark'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:210:in `find_asset'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:119:in `block in compile'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:118:in `each'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/sprockets/manifest.rb:118:in `compile'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.1.3/lib/sprockets/rails/task.rb:61:in `block (3 levels) in define'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-2.11.0/lib/rake/sprocketstask.rb:146:in `with_logger'
       /tmp/build_868a3914-b83c-496d-b715-75262204c9cf/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.1.3/lib/sprockets/rails/task.rb:60:in `block (2 levels) in define'
       Tasks: TOP => assets:precompile
       (See full trace by running task with --trace)
 !
 !     Precompiling assets failed.
 !

 !     Push rejected, failed to compile Ruby app

To git@heroku.com:polar-wave-2691.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@heroku.com:polar-wave-2691.git'

And when I visit the Heroku site, it says: Application Error An error occurred in the application and your page could not be served. Please try again in a few moments.

If you are the application owner, check your logs for details.

So I checked my logs, which say:

Lisa:sample_app admin-lisa$ heroku logs
2014-06-27T00:07:21.685434+00:00 heroku[api]: Enable Logplex by somebody.lisa@gmail.com
2014-06-27T00:07:21.685490+00:00 heroku[api]: Release v2 created by somebody.lisa@gmail.com
2014-06-27T00:07:29+00:00 heroku[slug-compiler]: Slug compilation started
2014-06-27T00:07:33+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app
2014-06-27T00:07:40.377399+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=polar-wave-2691.herokuapp.com request_id=5b29dca1-29e3-4410-8efb-99c74f1b14ec fwd="50.143.161.142" dyno= connect= service= status=503 bytes=
2014-06-27T00:07:40.673553+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=polar-wave-2691.herokuapp.com request_id=39df86cb-8d9c-418f-afb9-8242fc5f311e fwd="50.143.161.142" dyno= connect= service= status=503 bytes=
2014-06-27T00:08:03.130094+00:00 heroku[api]: Starting process with command `rake db:migrate` by somebody.lisa@gmail.com
2014-06-27T00:08:04.869272+00:00 heroku[run.1405]: State changed from starting to up
2014-06-27T00:08:06.629224+00:00 heroku[run.1405]: State changed from up to complete
2014-06-27T00:08:04.809756+00:00 heroku[run.1405]: Starting process with command `rake db:migrate`
2014-06-27T00:08:06.612075+00:00 heroku[run.1405]: Process exited with status 1
2014-06-27T00:08:04.774227+00:00 heroku[run.1405]: Awaiting client
2014-06-27T00:08:10.068439+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=polar-wave-2691.herokuapp.com request_id=a6c649ff-2b4b-4a67-9bfa-c2e06b623c8a fwd="50.143.161.142" dyno= connect= service= status=503 bytes=
2014-06-27T00:08:10.354925+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=polar-wave-2691.herokuapp.com request_id=60a03227-4cfa-4ba3-b2e5-f84b63b0db07 fwd="50.143.161.142" dyno= connect= service= status=503 bytes=
2014-06-27T00:08:13.488700+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=polar-wave-2691.herokuapp.com request_id=21eb1930-2b7e-4e57-b0df-3fffaeffae29 fwd="50.143.161.142" dyno= connect= service= status=503 bytes=
2014-06-27T00:08:13.851121+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=polar-wave-2691.herokuapp.com request_id=9b015c1f-e710-4866-acba-0f215ea5938d fwd="50.143.161.142" dyno= connect= service= status=503 bytes=
2014-06-27T00:08:40.685450+00:00 heroku[run.2450]: Awaiting client
2014-06-27T00:08:40.746839+00:00 heroku[run.2450]: Starting process with command `rake db:migrate`
2014-06-27T00:08:39.220494+00:00 heroku[api]: Starting process with command `rake db:migrate` by jonsson.lisa@gmail.com
2014-06-27T00:08:40.730443+00:00 heroku[run.2450]: State changed from starting to up
2014-06-27T00:08:42.454908+00:00 heroku[run.2450]: State changed from up to complete
2014-06-27T00:08:42.363758+00:00 heroku[run.2450]: Process exited with status 1
2014-06-27T00:08:55.126228
+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=polar-wave-2691.herokuapp.com request_id=5f1ec80d-7dc1-4810-91a1-1f61b7f1dc66 fwd="50.143.161.142" dyno= connect= service= status=503 bytes=
2014-06-27T00:08:55.685930+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=polar-wave-2691.herokuapp.com request_id=03a9fa47-7148-4a12-b7ec-ffe2100f4161 fwd="50.143.161.142" dyno= connect= service= status=503 bytes=
2014-06-27T00:16:47.224352+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/" host=polar-wave-2691.herokuapp.com request_id=fccc625d-9bd2-4d2b-8d95-a51fe4d210eb fwd="50.143.161.142" dyno= connect= service= status=503 bytes=
2014-06-27T00:16:47.589404+00:00 heroku[router]: at=error code=H14 desc="No web processes running" method=GET path="/favicon.ico" host=polar-wave-2691.herokuapp.com request_id=336a9fd4-47c7-4342-a7c2-3815eb0b84d3 fwd="50.143.161.142" dyno= connect= service= status=503 bytes=
2014-06-27T00:17:01+00:00 heroku[slug-compiler]: Slug compilation started
2014-06-27T00:17:05+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app
2014-06-27T00:18:13+00:00 heroku[slug-compiler]: Slug compilation started
2014-06-27T00:19:08+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app
2014-06-27T00:20:16+00:00 heroku[slug-compiler]: Slug compilation started
2014-06-27T00:21:03+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app
2014-06-27T00:22:11+00:00 heroku[slug-compiler]: Slug compilation started
2014-06-27T00:22:39+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app
2014-06-27T00:23:31+00:00 heroku[slug-compiler]: Slug compilation started
2014-06-27T00:23:56+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app
2014-06-27T00:24:37+00:00 heroku[slug-compiler]: Slug compilation started
2014-06-27T00:25:06+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app
2014-06-27T00:26:09+00:00 heroku[slug-compiler]: Slug compilation started
2014-06-27T00:26:37+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app
2014-06-27T00:39:14+00:00 heroku[slug-compiler]: Slug compilation started
2014-06-27T00:39:51+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app

I don't understand what it's trying to tell me, exactly, but I tried to run

rake assets:precompile 

also

heroku run rake db:migrate

I also checked my git status and everything has been committed.

I tried deleting my gemfile.lock and running bundle again and rake db:migrate and committing it all over, but no luck.

I'm just learning Rails and the heroku log isn't totally making sense to me.

Thank you.

回答1:

What does your application.js file look like? If you are using turbolinks get rid of it. Rails may be trying to precompile your assets for you and minify them, but that may be tripping you up. Also check out https://github.com/heroku/rails_12factor, you may want to install this gem.



回答2:

I had a similar issue to this a few weeks ago when building my first rails app; I would go ahead and remove your sass-rails gem, along with the group assets do, re-bundle, and give it another shot.

Should look like this:

gem 'coffee-rails'
gem 'uglifier', '1.2.3' 

not

group :assets do 
  # Use SCSS for stylesheets
  gem 'sass-rails', '~> 4.0.3'
  gem 'coffee-rails'
  gem 'uglifier', '1.2.3' 
end 


回答3:

In your gemfile try adding gem 'rails_12factor' to production. So the code should change from

...
group :production do 
  gem 'pg'
end 

to

...
group :production do 
  gem 'pg'
  gem 'rails_12factor'
end 

Edit: Here is what my entire Gemfile

source 'https://rubygems.org'
gem 'rails', '4.1.1'
# Use sqlite3 as the database for Active Record 
# gem 'sqlite3'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer',  platforms: :ruby

# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more:         https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read      more: https://github.com/rails/spring
gem 'spring',        group: :development

# Deploying to Heroku
group :production do
  gem 'pg'
  gem 'rails_12factor'
end

group :development, :test do 
  gem 'sqlite3'
end


回答4:

Here are some of the things that solved it for me (thanks @plondon, that was a good eye!)

Since I took out turbolinks from my Gemfile, I also had to make sure that my application.css/.js was not using it. I cleaned out both files.

I also deleted my Gemlock.file and bundle installed again.

Finally, after a force-push it went through, particularly because my application.js was using Turbolinks when I didn't have it installed anymore.



回答5:

You can follow the steps:

  1. Remove the gem 'turbolinks' line from your Gemfile.
  2. Remove the //= require turbolinks from your app/assets/javascripts/application.js.
  3. Remove the two "data-turbolinks-track" => true hash key/value pairs from your app/views/layouts/application.html.erb

In your Gemfile

gem "foreman"
group :production, :staging do
  gem "rails_12factor"
  gem "rails_stdout_logging"
  gem "rails_serve_static_assets"
end

More details remove turbolink