Search code examples
ruby-on-railsrubywindowsruby-on-rails-5rake

rake db: commands show NoMethodError: undefined method `chomp' for nil:NilClass error


When rake db: commands are executed, it shows an error

warning: parser/current is loading parser/ruby26, which recognizes
warning: 2.6.7-compliant syntax, but you are running 2.6.2.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
C:/Ruby26-x64/bin/rake: No such file or directory - which yarn
rake aborted!
NoMethodError: undefined method `chomp' for nil:NilClass
C:/.../config/environment.rb:5:in `<main>'
Tasks: TOP => db:migrate => db:load_config => environment
(See full trace by running task with --trace)

This happens on a Windows10 machine, but the mac machine is working fine without errors. It's a Ruby on rails application. Here's the environment.rb:

# Load the Rails application.
require_relative 'application'

# Initialize the Rails application.
Rails.application.initialize!

Any help would be appreciated.

Edit: The output of running rake with the --trace flag to see where exactly the NoMethodError was coming from (rake --trace db:migrate):

rake --trace db:migrate
warning: parser/current is loading parser/ruby26, which recognizes
warning: 2.6.7-compliant syntax, but you are running 2.6.2.
warning: please see https://github.com/whitequark/parser#compatibility-with-ruby-mri.
** Invoke db:migrate (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
C:/Ruby26-x64/bin/rake: No such file or directory - which yarn
rake aborted!
NoMethodError: undefined method `chomp' for nil:NilClass
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/mjml-rails-4.6.1/lib/mjml.rb:68:in `check_for_yarn_mjml_binary'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/mjml-rails-4.6.1/lib/mjml.rb:44:in `valid_mjml_binary'
C:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/mjml-rails-4.6.1/lib/mjml/railtie.rb:13:in `block in <class:Railtie>'

Solution

  • Answering my own question:

    My team and I, on the investigation, found out that the versions specified in the Gemfile and Gemfile.lock were different. The versions had got upgraded explicitly, so we'd had to load a predefined Gemfile.lock, and bringing gems on the same version solved the issue. So, for anyone else facing this issue, please check the versions (of the Gemfile and Gemfile.lock).

    PS. To much of our surprise, it didn't actually have anything to do with the database config.