-
-
Notifications
You must be signed in to change notification settings - Fork 27k
[react-scripts] Fix module resolution for yarn linked components #6207
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
base: main
Are you sure you want to change the base?
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
@yhnavein It looks like some tests may need adjustment. |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Keep alive! |
After struggling with this issue for quite some time, the fix in this Pull Request resolved my issue, thank you! How can we help move this along? |
@SRandazzo there are failing tests |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Don't! |
We came across the very same issue, and we tried to figure out what was going on, i.e. why the tests were failing. After an intense investigation that lead us to get a better understanding of webpack and npm modules resolution, the reason why the tests fails boils down to this:
The reason why we end up in this situation is that |
This test error shows a real problem. All node modules with transitive dependences with a different version than the hoisted one will break. |
I just ran into this issue. I wonder if at the least there's a way to make it more visible that it's a problem with the way things are being linked rather than with the packages themselves? |
Absolutely waiting for this to be merged into possibly 3.3.1 rather than 3.4 |
@yhnavein can you confirm @domtoupin's issue? |
More than 2 years later, this is still a problem. It is currently impossible to use Only option is to eject and tweak webpack config 😞 Here's a fix if you consider ejecting: mui/material-ui#14760 (comment) |
You can still use a script editing webpack file : not ideal but far more better than ejecting. I use a specific commands for link like this :
|
Hi,
Let me describe briefly our situation first.
We are using React applications generated by CRA and we have a separate repository with components. This component repository is a monorepo handled for us by lerna (with yarn workspaces). Typescript is used everywhere. All components are having only
peerDependencies
- nodependencies
.This set up works pretty decently, but we struggled with strange issues when at least one component from monorepo is yarn linked into the CRA app. Linking components is an essential feature for us.
The problem appeared firstly by broken
styled-components
in our app and message that multiple instances ofstyled-components
package being in use at once and indeed there were multiple occurences of this package (and others too). Using a bundler in component's code and defining external packages does have no effect.Following PR contains a fix for our problem. While doing an investigation we found that other approach of a fix was already proposed (#5654), but sadly forgotten. And those 2 ways are generally very similar.
The problem is that in case of linked components, symlinks are created and by default Webpack resolves them as real paths. It means that while analyzing our custom package from monorepo, webpack is looking for dependent modules by going up and up in the folder hierarchy, but because it's a symlinked location he won't hit
node_modules
of our application first, butnode_modules
of the root of the component's monorepo. Webpack will include this is the bundle and moves on. Later webpack will hit our application's use of the problematic 3rd party lib, will do the same but it will reach app'snode_modules
and tadam - we have multiple versions of basically the same lib bundled. I hope that I understood and explained it well :)Turning off symlinks is one way. We changed slightly a module resolution by the webpack using a full path to application's
node_module
first. In our opinion it is less a breaking change. Optionally I can introduce an env variable that would prevent this from being a breaking change at all.Topic is open for discussion.
Thanks