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

Rails 6.0 uninitialized constant StripeEvent (NameError) #124

Open
tbcooney opened this issue Aug 19, 2019 · 3 comments
Open

Rails 6.0 uninitialized constant StripeEvent (NameError) #124

tbcooney opened this issue Aug 19, 2019 · 3 comments

Comments

@tbcooney
Copy link

I've been running into this issue more frequently the past few weeks, ever since I first implemented my Stripe work to handle subscriptions. Here is a trace of me trying to create a new controller.

ruby '2.6.3'
gem 'rails', '~> 6.0'
gem 'stripe_event', '~> 2.2'

Trace

rails g controller two_factors
/Users/taylorcooney/code/openunit/config/routes.rb:2:in `block in <main>': uninitialized constant StripeEvent (NameError)
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0.rc2/lib/action_dispatch/routing/route_set.rb:429:in `instance_exec'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0.rc2/lib/action_dispatch/routing/route_set.rb:429:in `eval_block'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/actionpack-6.0.0.rc2/lib/action_dispatch/routing/route_set.rb:411:in `draw'
	from /Users/taylorcooney/code/openunit/config/routes.rb:1:in `<main>'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/bootsnap-1.4.4/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:54:in `load'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0.rc2/lib/rails/application/routes_reloader.rb:41:in `block in load_paths'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0.rc2/lib/rails/application/routes_reloader.rb:41:in `each'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0.rc2/lib/rails/application/routes_reloader.rb:41:in `load_paths'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0.rc2/lib/rails/application/routes_reloader.rb:20:in `reload!'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0.rc2/lib/rails/application/routes_reloader.rb:30:in `block in updater'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/file_update_checker.rb:83:in `execute'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0.rc2/lib/rails/application/routes_reloader.rb:10:in `execute'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/railties-6.0.0.rc2/lib/rails/application/finisher.rb:197:in `block (2 levels) in <module:Finisher>'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:429:in `instance_exec'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:429:in `block in make_lambda'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:201:in `block (2 levels) in halting'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:607:in `block (2 levels) in default_terminator'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:606:in `catch'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:606:in `block in default_terminator'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:202:in `block in halting'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:514:in `block in invoke_before'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:514:in `each'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:514:in `invoke_before'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/callbacks.rb:134:in `run_callbacks'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.taylorcooney@CANTORJSW1-ML:~/code/openunit$ ⚡
0.0.rc2/lib/active_support/execution_wrapper.rb:111:in `run!'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/reloader.rb:114:in `run!'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/reloader.rb:53:in `block (2 levels) in reload!'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/reloader.rb:52:in `tap'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/reloader.rb:52:in `block in reload!'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/execution_wrapper.rb:88:in `wrap'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-6.0.0.rc2/lib/active_support/reloader.rb:51:in `reload!'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:168:in `serve'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:145:in `block in run'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:139:in `loop'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application.rb:139:in `run'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/spring-2.1.0/lib/spring/application/boot.rb:19:in `<top (required)>'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from /Users/taylorcooney/.rbenv/versions/2.6.3/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
	from -e:1:in `<main>'
@rmm5t
Copy link
Member

rmm5t commented Aug 20, 2019

This appears to be coming from your config/routes.rb file. Would you mind sharing the relevant portion that references StripeEvent in that file? Is it more than just something like:

Rails.application.routes.draw do
  # ...
  mount StripeEvent::Engine => "/webhooks/stripe"
  # ...
end

I don't have a Rails 6 project that uses StripeEvent at the moment.

If for some reason the autoloader isn't finding StripeEvent, you should be able to add a require statement to the top of your routes.rb:

require "stripe_event"

Worst case, if there's some other load order issue, you might need to add a more explicit require statement at the top of your routes.rb:

require "stripe_event/engine"

Of course, I wouldn't expect either of these requires to be necessary either.

@tbcooney
Copy link
Author

Hey @rmm5t - I've got StripeEvent mounted in the same way you referenced above. Let me add in a require and report back. To explain a little more, I'll try to start a console bundle exec rails c and I will get a uninitialized constant StripeEvent (NameError) error with the same trace above. I'll run the same bundle exec rails c command right after and it works.

@umar221b
Copy link

I am running into the same issue when I run rails routes.

My setup is as follows:

ruby: 2.7.1
rails: 6.1.1
stripe_event: 2.3.1

config/routes.rb:

Rails.application.routes.draw do
  mount Spree::Core::Engine, at: '/'

  mount StripeEvent::Engine at: '/stripe/hook'
end

Spree::Core::Engine.routes.draw do
 # more routes
end

Adding the require statements continued to show the same error.

Here is a trace:

$ rails routes
DEPRECATION WARNING: SolidusSupport::EngineExtensions::Decorators is deprecated! Use SolidusSupport::EngineExtensions instead. (called from <main> at /Users/umar/some_project/config/application.rb:20)
Traceback (most recent call last):
	58: from bin/rails:4:in `<main>'
	57: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
	56: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
	55: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
	54: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	53: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	52: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	51: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	50: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	49: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/commands.rb:18:in `<main>'
	48: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/command.rb:50:in `invoke'
	47: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/command/base.rb:69:in `perform'
	46: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor.rb:392:in `dispatch'
	45: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/invocation.rb:127:in `invoke_command'
	44: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/thor-1.0.1/lib/thor/command.rb:27:in `run'
	43: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/commands/routes/routes_command.rb:13:in `perform'
	42: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
	41: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/command/actions.rb:28:in `require_environment!'
	40: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/application.rb:360:in `require_environment!'
	39: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `require'
	38: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:299:in `load_dependency'
	37: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/dependencies.rb:332:in `block in require'
	36: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/zeitwerk-2.4.2/lib/zeitwerk/kernel.rb:34:in `require'
	35: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/polyglot-0.3.5/lib/polyglot.rb:65:in `require'
	34: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:31:in `require'
	33: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require_with_bootsnap_lfi'
	32: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
	31: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `block in require_with_bootsnap_lfi'
	30: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
	29: from /Users/umar/some_project/config/environment.rb:5:in `<main>'
	28: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/application.rb:384:in `initialize!'
	27: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/initializable.rb:60:in `run_initializers'
	26: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/2.7.0/tsort.rb:205:in `tsort_each'
	25: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/2.7.0/tsort.rb:226:in `tsort_each'
	24: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/2.7.0/tsort.rb:347:in `each_strongly_connected_component'
	23: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/2.7.0/tsort.rb:347:in `call'
	22: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/2.7.0/tsort.rb:347:in `each'
	21: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/2.7.0/tsort.rb:349:in `block in each_strongly_connected_component'
	20: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/2.7.0/tsort.rb:431:in `each_strongly_connected_component_from'
	19: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/2.7.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component'
	18: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/2.7.0/tsort.rb:228:in `block in tsort_each'
	17: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/initializable.rb:61:in `block in run_initializers'
	16: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/initializable.rb:32:in `run'
	15: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/initializable.rb:32:in `instance_exec'
	14: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/application/finisher.rb:195:in `block in <module:Finisher>'
	13: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/application/routes_reloader.rb:10:in `execute'
	12: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/activesupport-6.1.1/lib/active_support/file_update_checker.rb:83:in `execute'
	11: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/application/routes_reloader.rb:35:in `block in updater'
	10: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/application/routes_reloader.rb:21:in `reload!'
	 9: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/application/routes_reloader.rb:47:in `load_paths'
	 8: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/application/routes_reloader.rb:47:in `each'
	 7: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/railties-6.1.1/lib/rails/application/routes_reloader.rb:47:in `block in load_paths'
	 6: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
	 5: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/bootsnap-1.5.1/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:59:in `load'
	 4: from /Users/umar/some_project/config/routes.rb:3:in `<main>'
	 3: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/routing/route_set.rb:409:in `draw'
	 2: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/routing/route_set.rb:427:in `eval_block'
	 1: from /Users/umar/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/actionpack-6.1.1/lib/action_dispatch/routing/route_set.rb:427:in `instance_exec'
/Users/umar/some_project/config/routes.rb:19:in `block in <main>': undefined method `Engine' for StripeEvent:Module (NoMethodError)

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

3 participants