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

uninitialized constant ViewComponent #1972

Open
iamdriz opened this issue Jan 12, 2024 · 9 comments
Open

uninitialized constant ViewComponent #1972

iamdriz opened this issue Jan 12, 2024 · 9 comments

Comments

@iamdriz
Copy link

iamdriz commented Jan 12, 2024

Expected behavior

Installed view_component in the Gemfile (so it's definitely installed). And should be able to create components.

Actual behavior

ViewComponent doesn't seem to be being loaded in Rails as we get uninitialized constant ViewComponent

Not really sure where the problem is and what to try next... uninstalled the gem and re-installed it but same error.

Backtrace:

image

System configuration

Rails version: 6.1.7.6

Ruby version: 3.2.2

Gem version: 3.10.0

@iamdriz
Copy link
Author

iamdriz commented Jan 12, 2024

Seems the generator is broken as well:

bin/rails generate component Example title

As it returns the following error:

[WARNING] Could not load generator "rails/generators/component/component_generator". Error: uninitialized constant ViewComponent::Base.

Could it be an issue with the autoloading of the gem?

@iamdriz
Copy link
Author

iamdriz commented Jan 13, 2024

So I fixed it by adding require 'view_component' to application.rb

However I don't see any mention of having to do this in the installation guide... unless I missed it?

Would seem there's some auto load failing and then it requiring a manual load as I've done here.

@zulkufdemirhan
Copy link

So I fixed it by adding require 'view_component' to application.rb

However I don't see any mention of having to do this in the installation guide... unless I missed it?

Would seem there's some auto load failing and then it requiring a manual load as I've done here.

no need to add require 'view_component' to application.rb

@Spone
Copy link
Collaborator

Spone commented Jan 22, 2024

Hi @iamdriz that's weird. Can you double check the version of view_component in Gemfile.lock? Also, are you using the classic or zeitwerk mode? (See this guide)

@reeganviljoen
Copy link
Collaborator

@iamdriz do you have any further feedback on this issue, so that we know if this is still a bug on the view_component side or not

@iamdriz
Copy link
Author

iamdriz commented Feb 13, 2024

@Spone Its 3.10.0. I've not specified a version and I'm running Rails 6.1 so it should be defaulting to zeitwork in 6. It's defo loading the defaults from 6.1 as I have this in my application.rb, config.load_defaults 6.1

I also just ran: bin/rails runner 'p Rails.autoloaders.zeitwerk_enabled?' which prints true.

@iamdriz No I'm still having to manually require view_component in the application.rb file.

@iamdriz
Copy link
Author

iamdriz commented Feb 13, 2024

I'm looking at updating the app to 7.1 soon so will see if that fixes the issue.

@igillis-clara
Copy link

igillis-clara commented Apr 3, 2024

Did upgrading to 7.1 fix for you?

I just added ViewComponent to my 7.1 app, following the directions in the guide and got the same error. Edit: was just being dumb -- needed to restart server after installation

@reeganviljoen
Copy link
Collaborator

@iamdriz any further feedback

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

5 participants