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

webpack loader creates circular dependency when used with webpack-plugin-serve #1209

Closed
aaronjensen opened this issue Mar 22, 2019 · 5 comments
Assignees

Comments

@aaronjensen
Copy link

If you are reporting a bug or having an issue setting up React Hot Loader, please fill in below. For feature requests, feel free to remove this template entirely.

Description

When attempting to run an ejected create-react-app app with react-hot-loader and webpack-plugin-serve, there is a circular dependency load which causes the app to fail to load.

The load appears to come from the register() function injected by react-hot-loader/webpack. It seems that the register() function is being run immediately after react.js is evaluated, but before it is fully exported.

If I wrap the register function in a setTimeout, it works fine because the circular dependency is broken.

Expected behavior

What you think should happen:

It should work out of the box.

Actual behavior

What actually happens:

It doesn't, see description.

Environment

React Hot Loader version: 4.8.4

Run these commands in the project folder and fill in their results:

  1. node -v: 10.9.0
  2. npm -v: 6.8.0

Then, specify:

  1. Operating system: macOS 10.14.3
  2. Browser and version: Chrome 73

Reproducible Demo

https://github.com/aaronjensen/hot-serve-repro

@aaronjensen
Copy link
Author

I filed a related issue here: shellscape/webpack-plugin-serve#117 but I'm guessing the real problem is in react-hot-loader and webpack-plugin-serve is just doing something slightly different than the default webpack dev server which is causing this issue.

@theKashey
Copy link
Collaborator

Thanks for the demo. Probably I know what is broken.

@theKashey theKashey self-assigned this Mar 24, 2019
@shellscape
Copy link

@theKashey can you go into detail on what you think the cause is? is it something that can be fixed from within the plugin?

@theKashey
Copy link
Collaborator

Yeah, sorry - I really forget about this task :(
It's quite easy to fix it both from your side and RHL side - just exclude /node_modules\/(react|react-hot-loader)([\/]|$) from webpack-loader.
The same rule exists inside the babel-plugin, but missing in webpack-loader code.

@theKashey
Copy link
Collaborator

So

  • everything is bad. There is no way I could modify webpack-loader to break a cycle.
  • everything is good. There is a simple way how to modify your code, to prevent a cycle.

import 'react-hot-loader' before React. In your case - it's index.js

import 'react-hot-loader'; // <-------
import React from 'react';
import ReactDOM from 'react-dom';
// .....
ReactDOM.render(<App />, document.getElementById('root'));

You can also do the same trick by prefixing your entry with react-hot-loader/patch.js.

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

3 participants