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

Component generator is failing due ViewComponent::Base.generate being nil #1397

Open
kdiogenes opened this issue Jun 15, 2022 · 2 comments · May be fixed by #1291
Open

Component generator is failing due ViewComponent::Base.generate being nil #1397

kdiogenes opened this issue Jun 15, 2022 · 2 comments · May be fixed by #1291

Comments

@kdiogenes
Copy link

@kdiogenes kdiogenes commented Jun 15, 2022

Steps to reproduce

bin/rails g component Admin::Table title

Expected behavior

The generator runs successfully.

Actual behavior

[WARNING] Could not load generator "rails/generators/component/component_generator". Error: undefined method `locale' for nil:NilClass

   5  module Rails
   6    module Generators
   7      class ComponentGenerator < Rails::Generators::NamedBase
   8        include ViewComponent::AbstractGenerator
  10        source_root File.expand_path("templates", __dir__)
  12        argument :attributes, type: :array, default: [], banner: "attribute"
  13        check_class_collision suffix: "Component"
  15        class_option :inline, type: :boolean, default: false
❯ 16        class_option :locale, type: :boolean, default: ViewComponent::Base.generate.locale
  18        class_option :preview, type: :boolean, default: ViewComponent::Base.generate.preview
  19        class_option :sidecar, type: :boolean, default: false
  20        class_option :stimulus, type: :boolean, default: ViewComponent::Base.generate.stimulus_controller
  22        def create_component_file
  24        end
  63      end
  64    end
  65  end

.
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/view_component-2.57.0/lib/rails/generators/component/component_generator.rb:16:in `<class:ComponentGenerator>'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/view_component-2.57.0/lib/rails/generators/component/component_generator.rb:7:in `<module:Generators>'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/view_component-2.57.0/lib/rails/generators/component/component_generator.rb:6:in `<module:Rails>'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/view_component-2.57.0/lib/rails/generators/component/component_generator.rb:5:in `<main>'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/elastic-apm-3.8.0/lib/elastic_apm/spies.rb:91:in `require'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/dead_end-1.1.7/lib/dead_end/auto.rb:21:in `require'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/dead_end-1.1.7/lib/dead_end/auto.rb:50:in `require'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/command/behavior.rb:82:in `block (2 levels) in lookup'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/command/behavior.rb:78:in `each'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/command/behavior.rb:78:in `block in lookup'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/command/behavior.rb:77:in `each'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/command/behavior.rb:77:in `lookup'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/generators.rb:250:in `find_by_namespace'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/generators.rb:267:in `invoke'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/commands/generate/generate_command.rb:24:in `perform'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/thor-1.1.0/lib/thor/command.rb:27:in `run'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/thor-1.1.0/lib/thor/invocation.rb:127:in `invoke_command'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/thor-1.1.0/lib/thor.rb:392:in `dispatch'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/command/base.rb:63:in `perform'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/command.rb:44:in `invoke'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/railties-5.1.7/lib/rails/commands.rb:16:in `<main>'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `block in require_with_bootsnap_lfi'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/loaded_features_index.rb:65:in `register'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:20:in `require_with_bootsnap_lfi'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.3.2/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:29:in `require'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/activesupport-5.1.7/lib/active_support/dependencies.rb:292:in `block in require'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/activesupport-5.1.7/lib/active_support/dependencies.rb:258:in `load_dependency'
/home/kadu/.asdf/installs/ruby/2.5.8/lib/ruby/gems/2.5.0/gems/activesupport-5.1.7/lib/active_support/dependencies.rb:292:in `require'
bin/rails:4:in `<main>'

System configuration

Rails version: 5.1.7

Ruby version: 2.5.8

Gem version: 2.7.6.2

@Spone
Copy link
Collaborator

@Spone Spone commented Jun 15, 2022

Hi! Thanks for reporting this issue. We are currently working on a fix: #1291

@Spone Spone linked a pull request Jun 15, 2022 that will close this issue
@kdiogenes
Copy link
Author

@kdiogenes kdiogenes commented Jun 17, 2022

I tried to create an initializer with:

Rails.application.configure do
  config.view_component.generate ||= ActiveSupport::OrderedOptions.new(false)
  config.view_component.generate.stimulus_controller = true
  config.view_component.generate.locale = true
  config.view_component.generate.distinct_locale_files = true
  config.view_component.generate.preview = true
end

And discovered that :view_component_path is also nil. After also adding config.view_component.view_component_path = "app/components" to my configuration I was able to run the generator successfully.

@Spone, is this a good workaround?

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.

2 participants