Rails: NameError: uninitialized constant Rails::Application::YAML

2.1k Views Asked by At

I was trying to deploy my application to heroku and got this error. I've been googling around and haven't see anyone with a YAML issue so thought I ask online. Any help would be greatly appreciated

 remote: -----> Preparing app for Rails asset pipeline
 remote:        Running: rake assets:precompile
 remote:        rake aborted!
 remote:        NameError: uninitialized constant Rails::Application::YAML
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:377:in `secrets'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/config/environments/production.rb:2:in `block in <top (required)>'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/railtie.rb:210:in `instance_eval'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/railtie.rb:210:in `configure'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/config/environments/production.rb:1:in `<top (required)>'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:598:in `block (2 levels) in <class:Engine>'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:597:in `each'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/engine.rb:597:in `block in <class:Engine>'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in `each'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:44:in `tsort_each_child'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/initializable.rb:54:in `run_initializers'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:352:in `initialize!'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/config/environment.rb:5:in `<top (required)>'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:328:in `require'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:328:in `require_environment!'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/railties-4.2.0/lib/rails/application.rb:443:in `block in run_tasks_blocks'
 remote:        /tmp/build_78ce680a858c094f796e2b21b5bb1826/vendor/bundle/ruby/2.0.0/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define'
 remote:        Tasks: TOP => environment
 remote:        (See full trace by running task with --trace)

Checking out my heroku logs

 2015-06-07T00:58:16.085579+00:00 heroku[slug-compiler]: Slug compilation started
 2015-06-07T00:58:16.085600+00:00 heroku[slug-compiler]: Slug compilation failed: failed to compile Ruby app
4

There are 4 best solutions below

0
On

I am not quite sure what happened but I did a

require 'yaml'

in my production.rb file and it worked. I do not know why it is working but will update if I find out.

0
On

I added require 'yaml' to development.rb, production.rb and test.rb just to be on the safe side. Works fine now. Ruby 2.3.3 and Rails 4.2.0

0
On

There is a bug in some versions of rails ( 4.2.1 and 4.2.2 that I know of) There is a missing require 'yaml' statement in the file in the first line of the error message. On a VPS you can insert it yourself, but I am not sure how to do it with Heroku. When I raised it on GitHub I was advised to upgrade to the next rails version...

0
On

I had this issue when working on a legacy Rails 2.3 application with Docker.

I was running into this error whenever I start up the application using the command docker-compose up:

web_1  | App 61 output: Error: The application encountered the following error: uninitialized constant YAML (NameError)
web_1  | App 61 output:     /workdir/config/environment.rb:13:in `block in <top (required)>'
web_1  | App 61 output:     /usr/local/bundle/bundler/gems/rails-3ce754b1f962/railties/lib/initializer.rb:113:in `run'
web_1  | App 61 output:     /workdir/config/environment.rb:3:in `<top (required)>'
web_1  | App 61 output:     config.ru:2:in `require'
web_1  | App 61 output:     config.ru:2:in `block in <main>'
web_1  | App 61 output:     /usr/local/bundle/gems/rack-1.4.7/lib/rack/builder.rb:51:in `instance_eval'
web_1  | App 61 output:     /usr/local/bundle/gems/rack-1.4.7/lib/rack/builder.rb:51:in `initialize'
web_1  | App 61 output:     config.ru:1:in `new'
web_1  | App 61 output:     config.ru:1:in `<main>'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:101:in `eval'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:101:in `preload_app'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:189:in `block in <module:App>'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb:378:in `run_block_and_record_step_progress'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:188:in `<module:App>'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:30:in `<module:PhusionPassenger>'
web_1  | App 61 output:     /usr/local/bundle/gems/passenger-6.0.5/src/helper-scripts/rack-preloader.rb:29:in `<main>'
web_1  | [ E 2020-10-25 17:55:09.8091 27/Tc age/Cor/App/Implementation.cpp:221 ]: Could not spawn process for application /workdir: The application encountered the following error: uninitialized constant YAML (NameError)

Here's how I fixed it:

On Rails 2.3 add the following in your config/environment.rb:

require 'yaml'

On Rails 3.2 or Rails 4.2, add the following in your config/application.rb:

require 'yaml'

That's all.

I hope this helps