react-native-reanimated: False positive "Multiple versions of Reanimated" because of local .yarn cache in 2.10.0

Description

Hi, I’m getting an error Multiple versions of Reanimated were detected on my gitlab runner environment. I’m using local .yarn cache in the root of the project.

iOS:

[!] Invalid `Podfile` file: 
[!] Invalid `RNReanimated.podspec` file: [Reanimated] Multiple versions of Reanimated were detected. Only one instance of react-native-reanimated can be installed in a project. You need to resolve the conflict manually. Check out the documentation: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/troubleshooting#multiple-versions-of-reanimated-were-detected 

Conflict between: 
- /.yarn/v6/npm-react-native-reanimated-2.10.0-ed53be66bbb553b5b5e93e93ef4217c87b8c73db-integrity/node_modules/react-native-reanimated
- /node_modules/react-native-reanimated
.

Android:

* What went wrong:
A problem occurred evaluating project ':react-native-reanimated'.
> 
  Multiple versions of Reanimated were detected. Only one instance of react-native-reanimated can be installed in a project. You need to resolve the conflict manually. Check out the documentation: https://docs.swmansion.com/react-native-reanimated/docs/fundamentals/troubleshooting#multiple-versions-of-reanimated-were-detected 
  
  Conflict between: 
  - /.yarn/v6/npm-react-native-reanimated-2.10.0-ed53be66bbb553b5b5e93e93ef4217c87b8c73db-integrity/node_modules/react-native-reanimated
  - /node_modules/react-native-reanimated
  


My project, however, resolves to 2.10.0 only:

yarn why v1.22.19
[1/4] 🤔  Why do we have the module "react-native-reanimated"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "react-native-reanimated@2.10.0"
info Has been hoisted to "react-native-reanimated"
info This module exists because it's specified in "dependencies".
info Disk size without dependencies: "27.16MB"
info Disk size with unique dependencies: "27.36MB"
info Disk size with transitive dependencies: "32.86MB"
info Number of shared dependencies: 40
✨  Done in 0.32s.

Shouldn’t the yarn/npm cache be excluded from the duplicities check? Or maybe it should search only in the scope of the root node_modules ?

Steps to reproduce

iOS

  1. have a project with one installation of rn-reanimated of 2.10.0
  2. rm -rf node_modules
  3. yarn install --cache-folder .yarn
  4. cd ios
  5. pod install
  6. error ❌

Android

  1. have a project with one installation of rn-reanimated of 2.10.0
  2. rm -rf node_modules
  3. yarn install --cache-folder .yarn
  4. react-native run-android
  5. error ❌

Snack or a link to a repository

🤷‍♂️

Reanimated version

2.10.0

React Native version

0.69.4

Platforms

Android, iOS

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Paper (Old Architecture)

Build type

No response

Device

No response

Device model

No response

Acknowledgements

Yes

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 20 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Hey, upgrade to 2.12.0 and the issue will be gone.

Nope. The issue only started for us with 2.12.0 - although other dependencies also changed. Something about react-native-reanimated causes yarn to install it into two places with a monorepo, in very particular circumstances.

Specifically, when @babel/core is listed as a devDependencies in our subpackage, then the [root]/node_modules and the [root]/packages/[package-name]/node_modules both will contain react-native-reanimated - even if we specify it in nohoist.

Any ideas? We’re experiencing this due to a bug in Yarn, I guess, but I can’t find any way around it with Expo because eas prebuild forcibly add the problematic devDependency and subsequently react-native-reanimated will be installed in two places.


Edit:

I found a solution! Note that this specifically is for Expo users with a monorepo. If that doesn’t describe you, this isn’t the solution you’re looking for.

Solution: Manually add @babel/core to devDependencies with a version matching your monorepo’s version - then expo prebuild will not disturb it.

Works!

I noticed the PR is based on 3.0.0-rc.2. So I verified 3.0.0-rc.2 also gave the error. It does.

Specifying your PR:

    "react-native-reanimated": "https://github.com/software-mansion/react-native-reanimated#874792921f64f526899fad9c39b168458813570b",

makes pod install behave again.

@Slapbox Have you manually added @babel/core to devDependencies or [root]/packages.json or [root]/packages/[package-name]/packages.json ?

Should we use the custom PR link until the official patch is published?

Sure, go ahead, but note that the PR is based on 3.0.0-rc.2.

If you use Reanimated 2.x, I recommend using patch-package (at least until we backport this PR to the 2.x branch).

Hey @honzajerabek, thanks for reporting this issue! We will investigate it.

Thanks! In my case I was needing react-native-reanimated to not be hoisted, as I have a patch applied. What worked for me was listing the other libraries that were depending on react-native-reanimated in the nohoist section.

"nohoist": [
  "**/react-native-reanimated",
  "**/react-native-reanimated-carousel",
  "**/@gorhom/bottom-sheet"
]

No, no, I’ve double-checked it a few times.

I have this error reproduced on 2.12.0. I was able to fix it by installing the version yarn add react-native-reanimated@3.0.0-rc.2

@tomekzaw works also for me! 🙌 thanks