Skip to content
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

Can't load local gems with dashes #9

Open
alagos opened this issue Feb 12, 2018 · 2 comments · May be fixed by #11
Open

Can't load local gems with dashes #9

alagos opened this issue Feb 12, 2018 · 2 comments · May be fixed by #11

Comments

@alagos
Copy link

alagos commented Feb 12, 2018

If I create a new project with require_reloader

rails new lala

and I'm creating a gem with a dash in its name, let's say:

bundle gem foo-bar

then load the gem changing the Gemfile like:

gem 'foo-bar', path: '../foo-bar'

it throws:

/home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require': cannot load such file -- foo-bar (LoadError)
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/require_reloader-0.2.1/lib/require_reloader.rb:58:in `block (2 levels) in watch'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:413:in `instance_exec'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:413:in `block in make_lambda'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:197:in `block (2 levels) in halting'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:601:in `block (2 levels) in default_terminator'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:600:in `catch'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:600:in `block in default_terminator'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:198:in `block in halting'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:507:in `block in invoke_before'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:507:in `each'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:507:in `invoke_before'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:130:in `run_callbacks'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/activesupport-5.1.4/lib/active_support/reloader.rb:87:in `prepare!'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/application/finisher.rb:61:in `block in <module:Finisher>'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `instance_exec'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/initializable.rb:30:in `run'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/initializable.rb:59:in `block in run_initializers'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in `each'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in `call'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/initializable.rb:58:in `run_initializers'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/application.rb:353:in `initialize!'
        from /home/alter/temp/lala/config/environment.rb:5:in `<top (required)>'
        from config.ru:3:in `require_relative'
        from config.ru:3:in `block in <main>'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/rack-2.0.4/lib/rack/builder.rb:55:in `instance_eval'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/rack-2.0.4/lib/rack/builder.rb:55:in `initialize'
        from config.ru:in `new'
        from config.ru:in `<main>'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/rack-2.0.4/lib/rack/builder.rb:49:in `eval'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/rack-2.0.4/lib/rack/builder.rb:49:in `new_from_string'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/rack-2.0.4/lib/rack/builder.rb:40:in `parse_file'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/rack-2.0.4/lib/rack/server.rb:319:in `build_app_and_options_from_config'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/rack-2.0.4/lib/rack/server.rb:219:in `app'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:24:in `app'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/rack-2.0.4/lib/rack/server.rb:354:in `wrapped_app'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:80:in `log_to_stdout'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:42:in `start'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:135:in `block in perform'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `tap'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/commands/server/server_command.rb:130:in `perform'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
        from /home/alter/temp/lala/bin/rails:9:in `require'
        from /home/alter/temp/lala/bin/rails:9:in `<top (required)>'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `load'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/spring-2.0.2/lib/spring/client/rails.rb:28:in `call'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/spring-2.0.2/lib/spring/client/command.rb:7:in `call'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/spring-2.0.2/lib/spring/client.rb:30:in `run'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/spring-2.0.2/bin/spring:49:in `<top (required)>'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `load'
        from /home/alter/.rvm/gems/ruby-2.4.2@default/gems/spring-2.0.2/lib/spring/binstub.rb:31:in `<top (required)>'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
        from /home/alter/.rvm/rubies/ruby-2.4.2/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb:68:in `require'
        from /home/alter/temp/lala/bin/spring:15:in `<top (required)>'
        from bin/rails:3:in `load'
        from bin/rails:3:in `<main>'

with an absolute path is the same story.

@AndrewRayCode
Copy link

Same issue, blocks all my gem loading as they're prefixed with a namespace

@maxivak
Copy link

maxivak commented Jul 7, 2019

If you are working with your gem locally and can modify it then you can change autoload_paths for your gem inside gem:

#/lib/mygem.rb
module OurGem
  if defined?(Rails)
    require 'mygem/engine'
  else
    require 'mygem/mystuff'
  end
end
#/lib/mygem/engine.rb
module Mygem
  class Engine < ::Rails::Engine
    config.autoload_paths += Dir["#{config.root}/lib/**/"]
  end
end

In my case my gem was a simple gem which can be used without Rails.
I tried to add gem's directories to autoload_paths and it didn't work.
Even I added my paths directly

mygem_base_path = '/local/path/to/gem/lib'
config.autoload_paths += Dir[mygem_base_path]
config.autoload_paths += Dir[File.join(mygem_base_path, "**/"]

@ryu-sato ryu-sato linked a pull request Mar 21, 2020 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants