-
-
Notifications
You must be signed in to change notification settings - Fork 631
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 ReactOnRails::WebpackerUtils::Webpacker upgrading to react-on-rails to 12.0 #1329
Comments
Hi @frankliu81, Did you include the rails/webpacker gem in your Gemfile? Are you on Rails 5+?
That's certainly not the case for many versions. I highly recommend that you upgrade. Please join our Slack channel. Thanks, Justin |
Hi @justin808, No, not using rails/webpacker gem in our Gemfile, it's a ten year old app, we are on But I was following: As for ReactOnRails.register does not seem to work across the bundle files, the problem I was trying to solve was to include a shared global navigation bar component across different SPA app bundles. Before, we have just one webpack bundle
My first attempt:
==== Second Attempt:
It would be nice to know which react_on_rails version that this works, so I can upgrade to that without fully upgrade to webpacker for now. Thanks. |
Please join the slack channel with the invite on this page: https://www.shakacode.com/open-source-projects/. Then message me. |
In order to use React on Rails v12, you have to use the view helpers that put your webpack bundles on the view. There's no reason to use the legacy React on Rails v11 helpers, Regarding Hot reloadingYou have:
I recommend the example react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh for how to setup hot reloading. AFAIK, the definition of ReactOnRails.register has not changed for 4 years. So that's not your issue. I'm guessing that your update worked, and the cause of the initial problem was the split chunks plugin. In general, your updated configuration is much better (but no need to call register twice): ReactOnRails.register({
DashboardApp: hot(DashboardApp),
GlobalNavBar: hot(GlobalNavBar),
}); Also, I'd recommend refactoring your app so that your your DashboardApp has the GlobalNavBar (and footer) as a component and then have a separate layout where you want a Rails body and footer. Please let me know if you resolved the issue. There should be no reason that you can't upgrade to v12. |
@frankliu81 I think this issue may relate to what you saw: |
Thanks @justin808.
The callstack I posted in the first post was the reason I can't upgrade, and I follow
Our GlobalNavBar is actuallly meant to be global, so it is mounted in
The question then is for this common component, where to import and register it.
I can see in the browser New approach was: What I think is happening is calling ReactOnRails.register once each from two separate bundle files would just override one another (ie. the register call is not additive).
In that case, with the new approach, dashboard was loading before, but adding runtimeChunk: 'single' as above, then no react component loads for me, with no console output / errors to indicate what's wrong. |
Hi @frankliu81
There is no reason to not use the rails/webpacker view helpers. Using the webpack setup would be a much bigger challenge. However, you should stick to the basic helpers and avoid the split chunks options unless you are confident with that.
That's also related to loading the wrong bundle on the page if this is client side rendering. If this is for SSR, let me know.
Register call is definitely additive, but if you have different entry points and are code splitting, you'll see issues like this.
This would require some debugging. There are many possible reasons for issues. Check out https://www.shakacode.com/react-on-rails-pro and https://github.com/sponsors/shakacode. A small bit of custom debugging help could go a long way to accelerating this task. |
Ok, I guess it's worth exploring upgrading to webpacker. We have a rather large codebase, lots of different pieces need attention all the time, and the webpacker upgrade is not the biggest MOL item at the moment. But perhaps once we do take on the upgrade, I will revisit this, so I will close this for now. Thank you for your help. |
Upgrading to react_on_rails from 6.1.1 to 12.0.2, we are not using webpacker I get a, uninitialized constant:
I did follow:
https://github.com/shakacode/react_on_rails/blob/master/docs/basics/upgrading-react-on-rails.md
Without integrating webpacker
• Bump your ReactOnRails versions in Gemfile & package.json
• In /config/initializers/react_on_rails.rb:
- Rename config.npm_build_test_command ==> config.build_test_command
- Rename config.npm_build_production_command ==> config.build_production_command
- Add config.node_modules_location = "client"
The reason for upgrade is I am trying to split our webpack into multiple bundles, but the ReactOnRails.register does not seem to work across the bundle files. I tried the workaround mention here by attaching ReactOnRails to windows, but that didn't work either: #991, so I am trying to see if upgrading might fix this.
The text was updated successfully, but these errors were encountered: