byCedric / expo-monorepo-example

Fast pnpm monorepo for cross-platform apps built with Expo / React Native and React.
https://docs.expo.dev/guides/monorepos/
MIT License
686 stars 72 forks source link

Hoisting react-native-reanimated causes the app to quite with duplicates error #81

Open kickbk opened 1 year ago

kickbk commented 1 year ago

If you add "react-native-reanimated": "~2.12.0" to dependencies in apps/mobile and in packages/feature-home, then react-native-reanimated will be installed inside node_modules of apps/mobile and in the root, but not in packages/feature-home.

I'm not entirely sure if this is intended. I thought when the versions match it will be hoisted to the root node_modules and should not install in apps/mobile?

Regardless, when you then build the app and install it, then try to run it, it will crash during the splash screen and complain about multiple versions of react-native-reanimated.

This is true for several other packages.

Interestingly enough, if you add "react-native-elements": "^4.0.0-rc.2" for instance to dependencies of both apps/mobile and packages/feature-home, then that package will not be installed in apps/mobile and only in the root.

So if this is how hoisting is supposed to work, then it doesn't work for all packages. Not sure why not.

rrebase commented 1 year ago

I've struggled with the same issue and nohoist options aren't working in pnpm if using node-linker=hoisted (https://github.com/pnpm/pnpm/discussions/5651)

kickbk commented 1 year ago

I've struggled with the same issue and nohoist options aren't working in pnpm if using node-linker=hoisted (pnpm/pnpm#5651)

Actually, we worked on that node-linker=hoisted issue and it's resolved. Just update pnpm. I'm still facing the issue where hoisted packages end up getting installed in apps and packages instead of the root resulting in multiple versions. I just moved all dependencies to the apps, which works, but it kinda beats the purpose of hoisting.

rrebase commented 1 year ago

Actually, we worked on that node-linker=hoisted issue and it's resolved. Just update pnpm.

Can you link to the exact change/version that resolved it? 🙏 I can't seem to find any fixes related to this

kickbk commented 1 year ago

I'm using pnpm 7.26.3 and it works. However, unless installing the packages stalls for you, it's actually working. If it completed the installation and you're not seeing packages you expect to be hoisted get hoisted, then you're not alone ;) I ended up moving most packages to the app package.json.