excid3 / refer

Referral codes for Ruby on Rails applications
MIT License
219 stars 9 forks source link

[BUG] uninitialized constant Refer::HasReferrals (NameError) #7

Closed kieranklaassen closed 3 months ago

kieranklaassen commented 3 months ago

Bug Report

bin/rails generate refer:install
/Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/refer-0.5.0/lib/refer.rb:57:in `block in <main>': uninitialized constant Refer::HasReferrals (NameError)

  include Refer::HasReferrals
               ^^^^^^^^^^^^^^
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3/lib/active_support/lazy_load_hooks.rb:97:in `class_eval'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3/lib/active_support/lazy_load_hooks.rb:97:in `block in execute_hook'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3/lib/active_support/lazy_load_hooks.rb:87:in `with_execution_control'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3/lib/active_support/lazy_load_hooks.rb:92:in `execute_hook'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3/lib/active_support/lazy_load_hooks.rb:62:in `block in on_load'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3/lib/active_support/lazy_load_hooks.rb:61:in `each'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/activesupport-7.1.3/lib/active_support/lazy_load_hooks.rb:61:in `on_load'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/refer-0.5.0/lib/refer.rb:56:in `<main>'
    from <internal:/Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from <internal:/Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/zeitwerk-2.6.13/lib/zeitwerk/kernel.rb:34:in `require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/runtime.rb:60:in `block (2 levels) in require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/runtime.rb:55:in `each'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/runtime.rb:55:in `block in require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/runtime.rb:44:in `each'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler/runtime.rb:44:in `require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundler.rb:187:in `require'
    from /Users/kieranklaassen/rails/syncology/syncology-rails/config/application.rb:7:in `<main>'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-7.1.3/lib/rails/command/actions.rb:15:in `require_application!'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-7.1.3/lib/rails/command/actions.rb:19:in `boot_application!'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-7.1.3/lib/rails/commands/generate/generate_command.rb:21:in `perform'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor/command.rb:28:in `run'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor/invocation.rb:127:in `invoke_command'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-7.1.3/lib/rails/command/base.rb:178:in `invoke_command'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/thor-1.3.1/lib/thor.rb:527:in `dispatch'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-7.1.3/lib/rails/command/base.rb:73:in `perform'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-7.1.3/lib/rails/command.rb:71:in `block in invoke'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-7.1.3/lib/rails/command.rb:149:in `with_argv'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-7.1.3/lib/rails/command.rb:69:in `invoke'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/railties-7.1.3/lib/rails/commands.rb:18:in `<main>'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/3.3.0/bundled_gems.rb:74:in `block (2 levels) in replace_require'
    from /Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/bootsnap-1.18.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
    from bin/rails:4:in `<main>'

To Reproduce:

❯ bundle add refer ❯ bin/rails generate refer:install

Expected Behavior:

To install

Actual Behavior:

Error:

/Users/kieranklaassen/.rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/refer-0.5.0/lib/refer.rb:57:in `block in

': uninitialized constant Refer::HasReferrals (NameError)

excid3 commented 3 months ago
Screenshot 2024-07-22 at 12 08 12 PM

Works for me?

kieranklaassen commented 3 months ago

Let me try figure out more, maybe the version of JSP or rails. I'll get back to you

excid3 commented 3 months ago

Reopen if you figure it out 👍

vkazakevich commented 3 months ago

The problem in the conflict between https://github.com/honeybadger-io/heya and Refer. It seems that if both of these gems are installed, any CLI command returns the error uninitialized constant Refer::HasReferrals (NameError).

I experimented with my fork, and if I explicitly specify the path to this file, the error no longer appears. However, I’m not sure if this is the correct solution in this case.

I've added require_relative "../app/models/concerns/refer/has_referrals" to lib/refer.rb:4

https://github.com/vkazakevich/refer/commit/04232fcc16efd753c0492452c2d41f6e870bf5a6

vkazakevich commented 3 months ago
image