-
Notifications
You must be signed in to change notification settings - Fork 194
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
fix: resolve react-refresh/runtime to an absolute path #230
Conversation
I'm not sure if I understand this correctly - but we currently already mark I'm quite sure that this actual change won't cause much harm in effect, but I just want to understand the situation a bit more cause I think it is actually CRA that falls into the "configuration generator" category but not us. |
Sort of, before this PR it didn't actually require it, whichever file it was injected into did, resolving it up front like this makes sure that it uses the version provided to it through the peerDependency.
Imagine for a moment that there is no hoisting, that will give a layout like this:
Now |
Hiya 👋 (note that @merceyz is a Yarn maintainer as well and has plenty of context on hoisting, dependencies, etc 😃)
You do, and as a result it's perfectly fine if you require import {...} from 'react-refresh/runtime'; On PnP installs this translates into a hard error, whereas on npm installs this would silently "work", but there would be no guarantee as to the version of The fix @merceyz made, that calls |
Thanks for the clarifications (to both of you)! I'll merge this tomorrow and hopefully push out a patch version soon. |
What's the problem this PR addresses?
The webpack loader injects a
require
statement toreact-refresh/runtime
into the users code without resolving it to an absolute path first.Read https://yarnpkg.com/advanced/rulebook#packages-should-only-ever-require-what-they-formally-list-in-their-dependencies for more details on hoisting
This currently breaks Yarn PnP support in
create-react-app
Why is this a problem?
Imagine for a moment that there is no hoisting, that will give a layout like this:
Now
@pmmmwh/react-refresh-webpack-plugin
injectsrequire('react-refresh/runtime')
into/src/index.js
which webpack can't find so it fails, with this change it's injected asrequire('/node_modules/react-scripts/node_modules/react-refresh/runtime')
which webpack can findHow did you fix it?
require.resolve
the import toreact-refresh/runtime
to make sure the same version is always used