Skip to content

Rails - Can't run rails server with spring gem #610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wowremywang opened this issue Jan 24, 2020 · 8 comments
Closed

Rails - Can't run rails server with spring gem #610

wowremywang opened this issue Jan 24, 2020 · 8 comments

Comments

@wowremywang
Copy link

wowremywang commented Jan 24, 2020

When I could run the rails project yesterday on local.
But today I can't run the project with the below issues.
I haven't done anything.
I am using Spring 2.1.0

    $ rails s
    => Booting Puma
    => Rails 5.2.4.1 application starting in development 
    => Run `rails server -h` for more startup options
    Exiting
    You've tried to invoke Spring when it's already loaded (i.e. the Spring constant is defined).
    
    This is probably because you generated binstubs with Spring 1.0, and you now have a Spring version > 1.0 on your system. To solve this, upgrade your bundle to the latest Spring version and then run `bundle exec spring binstub --all` to regenerate your binstubs. This is a one-time step necessary to upgrade from 1.0 to 1.1.
    
    Here's the backtrace:
    
    /Users/admin/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
    /Users/admin/.rvm/gems/ruby-2.5.0/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
    /Users/admin/.rvm/gems/ruby-2.5.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `block in load'
    /Users/admin/.rvm/gems/ruby-2.5.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:257:in `load_dependency'
    /Users/admin/.rvm/gems/ruby-2.5.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:285:in `load'
    /Users/admin/.rvm/gems/ruby-2.5.0/gems/spring-2.1.0/lib/spring/binstub.rb:11:in `<top (required)>'
    /Users/admin/.rvm/rubies/ruby-2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:92:in `require'
    /Users/admin/.rvm/rubies/ruby-2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:92:in `require'
    /work/halfhelix/floravere/heroku_floravere_dev/bin/spring:15:in `<top (required)>'
    bin/rails:3:in `load'
    bin/rails:3:in `<main>'

I know this issue is a commonly known issue.

I have researched to fix issues but I couldn't fix it.

Anyone had this issue before?

@wowremywang
Copy link
Author

This issue was a code issue.

In app/helpers/api/v1/product_helper.rb, I have included undefined CONSTANT.

module Api::V1::ProductHelper
  include API::V1::LogHelper         # This is wrong. Api::V1::LogHelper is correct
  .....
end

I found this issue after removing the loading spring code in bin/rails.

bin/rails

#!/usr/bin/env ruby
begin
  load File.expand_path('../spring', __FILE__)
rescue LoadError => e
  raise unless e.message.include?('spring')
end
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

to

#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'

So I saw this issue.

....
/Users/admin/.rvm/gems/ruby-2.5.0/gems/activesupport-5.2.4.1/lib/active_support/dependencies.rb:511:in `load_missing_constant': Unable to autoload constant API::V1::LogHelper, expected /work/halfhelix/project/app/helpers/api/v1/log_helper.rb to define it (LoadError)

So I fixed In app/helpers/api/v1/product_helper.rb

module Api::V1::ProductHelper
  include Api::V1::LogHelper
  .....
end

Now I can run rails server. 🎉

@tmr08c
Copy link

tmr08c commented Mar 13, 2020

@yu-coder if I'm understanding your resolution correctly, it sounds like you were able to make changes within your app to fix the issue. If that's the case, would it make sense to close this issue?

@wowremywang
Copy link
Author

@tmr08c yes, I could fix this issue. Closing now.

@stankobrus
Copy link

sudo apt-get install git-core zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs yarn

yarn install --check-files

@roolo
Copy link

roolo commented Sep 6, 2020

I don't think this issue is fixed. Rails says you should upgrade Spring, but the problem is in your code. How was this issue addressed?

@HanyMoh
Copy link

HanyMoh commented Dec 13, 2020

Follow the steps below to install the new Spring and resolve the issue, Actually, I tried these steps but didn't work until I removed the tmp/cache and vendor/bundle:

  • run this bin/spring binstub --remove --all
  • remove the gem from Gemfile
  • run bundle install.
  • now add the gem "spring", group: :development in Gemfile
  • run bundle install
  • bundle exec spring binstub --all

@ashwin47
Copy link

I don't think this issue is fixed. Rails says you should upgrade Spring, but the problem is in your code. How was this issue addressed?

The idea here is to disable spring to check for all the code issues. Which was my case also.

@matthewgoodwin
Copy link

@norioumata Upgrading ruby caused my PG to upgrade to 1.1 (from .20). This prevented spring from running. Following this helped me troubleshoot the issue! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants