-
Notifications
You must be signed in to change notification settings - Fork 755
Cannot find component (Rails 5.1.2, webpacker, react-rails) #758
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
Comments
Hi! Thanks for the great bug report. What if you add
? I think webpack does some magic with the |
Thanks for the quick reply! That does not work. It changes the last error to "Cannot find component: 'PerformanceRow.jsx'" but otherwise it's the same. I also tried running |
Can you try accessing the Add to // Attach it to the window:
window.componentRequireContext = componentRequireContext Then in Chrome console, access the globally-available
If that doesn't return the react component, try a few variations, just in case a file extension might help. If that does return the component, then there must be some error in react-rails code which is messing up that lookup! |
Yep – here's my Chrome console:
|
Oh, however, I do have to add the extension to get The original error message from the helper is This leads me to believe that, somewhere, |
you're so right about that! Here's that lookup code: I think we could just treat |
I think requiring |
I'm not sure how to tell if the try {
// Load by name
} catch (err) {
// Load by name+.jsx
} ? |
Yep, that makes sense to me. In the call to |
yep, that's it! if it throws an error, i guess we just try again with a it's too bad, thinking how that will add some latency to every single page load. I can think of two ways to address that:
Or, leave it for later , which is also fine. apparently not too many folks have come across this bug 😬 |
If the original `fileName` search doesn't work, look for the file with `.jsx` on the end. This makes it possible to include `.jsx` files in the `app/javascript/components` directory and have `react-rails` find them automatically, importing their components.
Excellent! I've opened a PR #759 to fix this. This fix solves the issue on my local machine. I agree about the performance thing though. I'm not particularly savvy with js performance optimization, or with the react/webpack pipeline, so I'm not really the one to do that. But thanks for your help and I'm happy to test future things with this same app if needed. |
If you have this issue, and the above did not solve it, it may be because you previously installed react-rails to work with the rails asset pipeline, and then installed webpacker later. Removing I'm assuming that having |
I installed both at the same time, and didn't have either in the asset pipeline. In the original problem, |
It's the patch from reactjs#759 that was never merged to master, but I still need.
I'm facing the exact same issue at the moment. Had It's worth noting that I'm moving from the assets pipeline setup to Webpacker. I moved my |
Update: I was wrong about the above, it does work with
This seems a bit odd since I didn't read anything about adding folders in the |
Having almost the exact same issue. After following the fixes above, I've hit a dead end. Running
No combination of the component name, file extension, or folder path fixes this issue for me. Any ideas for a way forward? |
@BookOfGreg I run into this problem when I apply filtering to Unfortunately, I then run into a problem with I am happy to delve further into reproduction steps with you. |
@ecbrodie Did you end up solving that? I am in the same situation. |
I was forced to adjust my regex to allow directories to be included, as well as the JavaScript/Typescript files themselves:
I am not fond of this solution though, I feel like react-rails should be able to load components by name if the regex excludes directories but loads files. |
@ecbrodie That's true, thanks for the update. |
@ecbrodie This just worked but I don't understand why it did. I experimented for some hours without any success before trying your solution. Are you excluding the |
I switched jobs last year and no longer work on the project in question, nor work on a project using neither webpacker nor react-rails. Thus I am unable to comment further to this issue. |
Help us help you! Please choose one:
react-rails
, so I've included the stack trace and the exact steps which make it crash.react-rails
with another library, but I'm having trouble. I've described my JavaScript management setup (eg, Sprockets, Webpack...), how I'm trying to use this other library, and why it's not working.Essentially the same resulting problem as #757 and #713, where including my (haml) view helper
= react_component 'PerformanceRow'
gives me the following error messages:I've tried the following:
ReactRailsUJS
both above and belowimport "turbolinks"
andjavascript_include_tag "application.js"
in my mainviews/layouts/application.html.haml
, and removing/addingReactRailsUJS.detectEvents()
inapp/javascript/packs/application.js
.console.log(componentRequireContext.keys())
above theReactRailsUJS
initializer, which prints["./PerformanceRow.jsx"]
in my Chrome console.Here's my directory structure:
And some code:
As far as I can tell, I've double-checked capitalization and name-mangling, and
componentRequireContext
can definitely find the correct file. However,PerformanceRow
still seems to be unreachable. I can also accessReactRailsUJS
in the global context of the Chrome console.I should also mention that the default
hello_react.jsx
works just fine, but that the problem here seems to lie inReactRailsUJS
and the use of thecomponents/
directory. Tried to trim things as best I could, but let me know if I need to include any other information.The text was updated successfully, but these errors were encountered: