berry: [Bug?]: React Native monorepo support and yarn 3.1+

Self-service

  • I’d be willing to implement a fix

Describe the bug

Yarn 3.1.0 now hoists dependencies of dependencies when using installConfig.hoistingLimits: "workspaces".

This is a new behaviour compared to 3.0.2

This is breaking some setups, in my case with a React Native app in a monorepo. Metro (React Native bundler) expects all of its dependency tree to be in one unique node_module folder.

From the changelog I understand the previous behaviour might have been unwanted and 3.1.0 “optimized” things, but in practice it breaks setups that relied on it.

To reproduce

As this is a behaviour change and not a bug, I am not sure you need a way to easily reproduce it?

Environment

System:
    OS: macOS 12.0.1
    CPU: (8) x64 Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
  Binaries:
    Node: 16.13.0 - /private/var/folders/1b/wb5vmt3x7kg8gcgt4l11wbjm0000gn/T/xfs-981831cb/node
    Yarn: 3.1.0 - /private/var/folders/1b/wb5vmt3x7kg8gcgt4l11wbjm0000gn/T/xfs-981831cb/yarn
    npm: 8.1.0 - /usr/local/Cellar/node@16/16.13.0/bin/npm

Additional context

Should this be a feature request for a new hoistingLimits value for hoisting the whole dependency tree?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 33 (12 by maintainers)

Most upvoted comments

I have been able to test the monorepo instructions on this page: https://docs.expo.dev/guides/monorepos/

  • use expo/metro-config
  • updating XCode’s config to look at the correct node_packages folder (in the root of the repo) for the various build commands
  • add export PROJECT_ROOT=$PWD in the “Bundle React Native code and images” build step
  • add --no-jetifier to the android build command (Jetifier should no longer be needed on modern apps)

This allowed me to build my React Native app without the need for hoisting and with the latest yarn version 🎉

I recently switched to https://microsoft.github.io/rnx-kit/ and it handles a yarn 3 monorepo (with node_modules linker) correctly.

Mostly due to https://microsoft.github.io/rnx-kit/docs/tools/metro-resolver-symlinks

@jmarek-sky No, I did not manage to use PnP with React Native, we are still using the node_modules linker.

You should be able to look at how expo/metro-config configures Metro and copy it in your own config, I dont think they do anything specific to Metro here.

@cm-nutrien Check out the official Expo docs for configuring monorepos, they neither use nohoist nor yarn-expo-workspaces since Expo SDK 43: https://docs.expo.dev/guides/monorepos/

Sure, here are a few issues:

@larixer Sorry, you are right, its the other way around. I should not post issues just before going to sleep.

The issue I am encountering is with the Metro bundler (React Native). It does not have support for workspaces not symlinks and has its own resolution mechanism, so we are using metro-symlinked-deps to force it resolve all dependencies from its own node_modules.

As Yarn allows us to dont hoist anything for a workspace it worked fine, but now that those packages are there only through a symlink it no longer works. I tried to dig into Metro’s code (which depends on some internal jest packages…) but this has been an issue for years and multiple PRs tried to fix this, but it’s still an issue.

Do you think there could be a new hoistingLimits value in Yarn to enable this behaviour?

@larixer I am currently using 3.0.3 and this is not the case, the whole dependency tree for my package with nstallConfig.hoistingLimits: "workspaces" is in my packages’s directory node_modules.