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

NameError: uninitialized constant ViewComponent::Compiler #1468

Closed
kurt-mueller-osumc opened this issue Aug 15, 2022 · 7 comments · Fixed by #1471
Closed

NameError: uninitialized constant ViewComponent::Compiler #1468

kurt-mueller-osumc opened this issue Aug 15, 2022 · 7 comments · Fixed by #1471

Comments

@kurt-mueller-osumc
Copy link

Steps to reproduce

  1. Install the view_component gem, version 2.66
  2. Run bin/rails db:seed

Expected behavior

It should seed the database.

Actual behavior

An error is thrown:

$ bin/rails db:seed
rails aborted!
NameError: uninitialized constant ViewComponent::Compiler

      ViewComponent::Compiler.mode = if Rails.env.development? || Rails.env.test?
                   ^^^^^^^^^^
Did you mean?  Complex
/workspace/web/config/environment.rb:5:in `<main>'
Tasks: TOP => db:seed => db:load_config => environment
(See full trace by running task with --trace)

System configuration

Rails version: 7.0.3.1

Ruby version: 3.1.2p20

Gem version: 2.66

@boardfish
Copy link
Collaborator

Hey @kurt-mueller-osumc! I've just tried to replicate this using our replicate-bug environment and failed to do so. In addition to the steps you provided, I added a config line that sets ViewComponent::Compiler.mode in config/environments/development.rb.

Can you provide any further details about the environment you're experiencing this in so that we can help to resolve it for you?

@kurt-mueller-osumc
Copy link
Author

Hi Simon,

Thanks for the quick reply. I'm currently in the development environment. Could you tell me what was the line you added in development.rb? Thank you :)

@kurt-mueller-osumc
Copy link
Author

I fixed this by downgrading view_component from 2.66 to 2.61.

@joelhawksley
Copy link
Member

@ineu
Copy link

ineu commented May 9, 2023

Sorry for bumping the old thread, but this issue doesn't seem to be fixed. I see it in 3.0 as well:

=> Booting Puma
=> Rails 7.0.4.3 application starting in development
=> Run `bin/rails server --help` for more startup options
Exiting
/home/ineu/.gem/ruby/3.2.1/gems/view_component-3.0.0/lib/view_component/engine.rb:111:in `block in <class:Engine>': uninitialized constant ViewComp
onent::Compiler (NameError)

      ViewComponent::Compiler.mode = if Rails.env.development? || Rails.env.test?
                   ^^^^^^^^^^
Did you mean?  Complex

@ineu
Copy link

ineu commented May 9, 2023

Ah, nevermind. It is fixed, but to make it work I needed to change the Gemfile from

gem 'view_component', require: 'view_component/engine'

to

gem 'view_component'

@sdkilbo
Copy link

sdkilbo commented Jun 12, 2023

Ah, nevermind. It is fixed, but to make it work I needed to change the Gemfile from

gem 'view_component', require: 'view_component/engine'

to

gem 'view_component'

Worked for me, 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

Successfully merging a pull request may close this issue.

5 participants