-
Notifications
You must be signed in to change notification settings - Fork 153
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
Dependencies, that have react-native
as a peerDependency
, resolve to the wrong version of react-native
#22
Comments
Hi @todorone ! |
Thanks for reply, @mmazzarolo I marked it as |
Why are you marking it in the |
@mmazzarolo Does monorepo tools supports RN |
@mmazzarolo I think I can confirm this bug. I use example applications with different RN versions ( When I added Moreover in my applications I use strict versions: dependencies: {
"react-native-svg": "=12.2.0"
} app with dependencies: {
"react-native-svg": "=12.2.0"
} In [mobile-0.66.1]$ ls node_modules/react-native-svg/node_modules/
react-native // <--- 0.66.0 !!!!! I think the reason is that resolution algorithm sees that workspace occupied by invalid RN version and have no choice, but installed it into Thus "peerDependencies": {
"react": "*",
"react-native": ">=0.50.0"
} it can rightfuly install 0.66.0 version. What yarn does. |
As soon as I removed ├─┬ [email protected]
│ └── [email protected] deduped
└─┬ [email protected] |
@mmazzarolo Sorry for the delay, i put the simple repro - https://github.com/todorone/react-native-universal-monorepo with one simple commit of adding Result of running Please let me know if any further clarification is needed and thanks again for working on such a cool monorepo setup. |
@todorone Looks like this is exactly problem I described above. I briefly looks at solving this problem. The only way to fix this is to use |
Thanks for reporting all, these info are super helpful 👍 I'm gonna give it a try soon. Just FYI, @todorone :
Unless something changed in yarn or in the new react-native version, I'm pretty sure this is something that can be solved with some tweaking. It's not happening on all libs that depend on Also, just to clarify: I'll give it a try soon and get back to you. |
Here are my initial research results. FYI, there are many other peer-dependencies related bugs in Yarn Classic (yarnpkg/yarn#8113, yarnpkg/yarn#8606, yarnpkg/yarn#6483, yarnpkg/yarn#7486, yarnpkg/yarn#7572, and this). I see a few options to solve this issue in your cases and in the repo (in order of elegance, IMHO):
If you could play a bit with the first option and return with some feedback, that would be great 👍 (you might also wanna block |
@mmazzarolo Thanks for deep research. I've tried to use Then I tried yarn v3 and had great success 🚀 😮 Inside example application I see all dependencies to You can see commits adding Everything is working 🤟🏻 I can run example application under different React Native versions simultaneously. Also my monorepo packages are linked correctly by yarn (I see links to packages). I use quite a lot of native dependencies including "nohoist": [
"**/react",
"**/react-dom",
"**/react-native",
"**/react-native/**",
"**/react-native-web",
"**/react-native-svg",
"**/react-native-reanimated",
"**/react-native-gesture-handler",
"**/react-native-animateable-text",
"**/@react-navigation/native",
"**/@react-navigation/native-stack",
"**/react-native-screens",
"**/react-native-safe-area-context",
"**/@react-native-async-storage/async-storage"
] |
I'll check it tomorrow, but the idea here is to continue supporting Yarn Classic as well. |
It will be compatible in a way that using yarn classic will work. Globally installed yarn (no matter version) automatically runs per-project yarn (no matter version). It's the most bulletproof approach. Yarn v3 is using per-project setup (yarn classic also supports this). So global yarn will always pick up correct version from |
Not really? I mean, you'd still need to have Yarn 2+ installed to make this repo work. I wouldn't define it as "bulletproof" if we force people to have Yarn 2+ installed when we can fix it on our side (on react-native-monorepo-tools) and make it work on both Yarn Classic and Yarn 2+. To clarify: I don't have anything against Yarn 2+ and/or Yarn 2+ setups. I'm using it on my machine, I like it, and I know it's backward compatible 👍 Let me know if I'm missing anything 👍 |
react-native
as a dependency, resolve to one version of react-native
react-native
as a peerDependency
, resolve to one version of react-native
react-native
as a peerDependency
, resolve to one version of react-native
react-native
as a peerDependency
, resolve to the wrong version of react-native
I completely agree with @mmazzarolo that the best option is to do the best to maintain compatibility with Yarn classic if it's possible. There is a reason why Yarn 2+ has low adoption - there was a pretty heated discussion between the community(including Facebook and some other companies employees) and the current Yarn maintainer, which did not want to follow propositions of maintaining compatibility with the classic Yarn. In the case it's not possible at all, switching to the new Yarn is also the way, but there will be serious friction about it... |
There is a compatibility issues between yarn classic versions. For RN monorepo I had to switch to older version (1.22.* or so didn't work) because of some issue (don't remember details). So to ensure consistency (users might have different yarn classic versions installed) I embedded yarn code into project itself. No matter of what yarn version installed globally on user machine, as soon as you go to project directory So global yarn just redirects commands to yarn which located inside repository. |
So I'm not against proposed solution. Just wanted to mention there's that yarn feature exists (in yarn classic too). And to say that supporting Repository will always use correct (valid / tested) yarn version, no matter is it yarn classic or yarn v3. So repository can use yarn v3 and get all goodies for free, without compromising developer experience. |
here is nice and easy metro.config alternative to work with yarn v1. Took from this article https://engineering.brigad.co/react-native-monorepos-code-sharing-f6c08172b417 |
@serge-sky , yeah, seems similar to the fix I mentioned above 👍 PRs to the monorepo tools are welcome! |
Share my experience with But today I tried to patch native dependency which uses JSI C++ code https://github.com/ospfranco/react-native-quick-sqlite and it's completely broken. Native dependencies require exact package location (since they require native parts in C++ using "../../react-native/..." paths). But the story is even worse 😢 I can't even switch back to yarn classic for the exact repository. I just can't now develop native code (the happy part it's not mandatory for me). |
Thanks for such a great monorepo setup
It works great out of the box, but as soon as i started to add dependencies, that use
react-native
, it stopped working for me.[email protected]
)/reanimated/react-native => resolves to[email protected]
[email protected]
)/reanimated/react-native => resolves to[email protected]
instead of[email protected]
I tried all combination of
nohoist
andresolutions
, but i was not able to set version of nestedreact-native
dependency of dependencies of platforms. Any hints?The text was updated successfully, but these errors were encountered: