Setting up React Native Monorepo With Yarn Workspaces
Authors
Oskar Kwaśniewski
Software Developer
@
Callstack
A monorepo is a single repository that holds a multitude of projects with all their code and assets. While the projects can be related, they can be used independently by different teams.
Working with monorepos is very useful, especially when developing big and complex applications like super apps. Monorepos enable sharing the logic between a web app and a mobile app, for example.
In this article, we’re going to set up a basic structure for a monorepo in React Native.
Why use monorepo in React Native?
Thanks to react-native-web we can share every component so there’s no need to duplicate the code many times. This means easier dependency management, shorter CI times, and better collaboration between teams since the code can be shared.
The main advantage though is the possibility of sharing packages between React and React Native. Most of the time we decide to share only business logic, but thanks to React Native Web, we can also share some of the UI components.
Setting up Yarn workspaces
While setting up a monorepo, we have two options: we can either hoist the packages to the root level or prevent them from hoisting. Yarn workspaces have an option named nohoist which allows us to specify packages that aren’t hoisted. It depends on your use case but most of the time it’s better to hoist packages to the root level.
Alternatively, you can use npm workspaces, it should work the same.
Why it’s better to avoid using nohoist
Preventing packages from hoisting takes back the main advantage of monorepos which is sharing node_modules between repositories. When nohoist option is turned on, most of the time packages are duplicated inside the root level node_modules and inside the project level node_modules. Downloading packages multiple times can lead to longer CI/CD runs and higher costs.
Rearranging the project structure
In order to set up yarn workspaces, we need to restructure our project to suit the structure below. Projects need to be divided into separate folders and we should have root level package.json
your-project
packages
web // <- React app
mobile // <- React Native app
shared // <- Shared (includes files shared between mobile/web)
Note that private: true is required because workspaces are not meant to be published.
In the workspaces section, we define a work tree. We can pass there an array of glob patterns that should be used to locate the workspaces. So in the example above, every folder inside packages is defined as a workspace.
Creating a React Native project
Use command below to create a React Native project inside the packages folder:
$ npx react-native init ExampleApp --directory mobile --template react-native-template-typescript
In order for our app to work in a monorepo structure, we need to make sure that config files are pointing to the root level node_modules due to package hoisting.
We’re almost done with setting up the project. The last thing in the React Native app is to add watchFolders so metro knows where the linked node_modules are. The shared modules are symlinked by Yarn, and Metro started supporting symlinks from version 0.75.1, effectively being shipped with React Native 0.72. If you want to turn on symlinks right now, you can pass the experimental flag to your metro config:
module.exports = {
// ...
resolver: {
unstable_enableSymlinks: true // Turn on symlink support
Regardless of whether you are using symlinks, metro still requires us to list symlinked modules in the config, but this might change in the future. You can follow the discussion on GitHub.
Next, we need to add this package as a dependency in our react native project. So inside packages/mobile/package.json add @example-app/shared as a dependency.
Note that the version of the package must match the version specified inside packages/shared/package.json. Previously we defined that @example-app/shared version is 1.0.0.
A short recap of Codex events in Berlin, Wroclaw, Warsaw, Sopot, and Miami, plus what we learned from each format and where we want to go next.
Feb 5·Live Stream
Storybook Explained: From Basics to Advanced Workflows
Core Storybook concepts, stories and args, interaction testing, and how Storybook works in React Native projects.
Jan 29·Article
Announcing AI SDK Profiler for React Native
Announcing the AI SDK Profiler plugin for Rozenite DevTools. Capture OpenTelemetry spans from the Vercel AI SDK and inspect AI requests across on-device and cloud providers.
Nov 28·Talk
How I Hacked React Native DevTools (And Built a Plugin Framework)
Learn how React Native DevTools work under the hood, and how to inject custom plugins with clean hooks and no forks.
Sep 16·Talk
How I Hacked React Native DevTools (And Built a Plugin Framework)
Learn how React Native DevTools work under the hood, and how to inject custom plugins with clean hooks and no forks.
Jul 28·Article
Introducing Rozenite: A Plugin Framework for React Native DevTools
Build custom debugging panels inside React Native DevTools with Rozenite: a modular, TypeScript-ready plugin framework with full device-scoped support.
Feb 12·Article
How to Easily Create Native Libraries With Nitro and Turbo Modules
Learn how to optimize React Native performance with Turbo and Nitro Modules. Ditch the legacy bridge and master modern native module development.
Dec 4·Podcast
Radon IDE: Better Developer Experience for React Native Teams
Find out how Radon IDE can help increase team velocity and rid you of the common React Native app development pain points.
Sep 19·Podcast
Exploring Bun: Jarred Sumner on Hyperfast JavaScript Toolkit
Is Bun the future of React Native package management? Join us as we talk with Jarred Sumner, the creator of this lightning-fast JavaScript toolkit.
Sep 11·Podcast
Vim: from Zero to Hero
Discover the power of Vim, the legendary text editor, as we explore its origins, standout features, and practical tips to boost your coding efficiency.
May 15·Article
Add-Ons for Web Browsers With React
At times you may need to create an add-on to use a web browser more effectively. Find out how to build one with React.
Jan 27·Article
Why Is It Worth to Automate Your Dependency Management with `Autolinking`?
When you automate your dependency management, you can fully focus on developing your app. Find out how you can do it with autolinking.
Mar 19·Tutorial
The Hard Way vs. The React Native AI SDK Way: Stop Writing Custom Modules for Every Model
Learn how React Native AI uses a unified provider model to switch between cloud and on-device LLMs without rewriting application logic, enabling reliable AI experiences online and offline.
Mar 12·Tutorial
Build Smarter Apps: Tool Calling & AI Orchestration Explained
Learn how on-device models in React Native can call tools, interact with external APIs, and return structured outputs you can use directly in application logic.
Mar 5·Tutorial
MLC LLM + React Native: On-Device AI Without the Pain
Learn how to run third-party on-device LLMs in React Native using MLC LLM. Choose your models, run them efficiently across platforms, and keep a unified JavaScript API with React Native AI.
Feb 24·Tutorial
Intelligent Fallbacks with Apple Intelligence in React Native
Learn how to use Apple’s built-in Foundation Models in React Native apps, reduce memory usage, and enable fast, fully on-device AI with React Native AI Apple.
Feb 10·Tutorial
What Is the React Native AI SDK? A Complete Intro & Quickstart
Learn why on-device AI matters for React Native apps, how local LLMs behave offline, and what problems React Native AI is designed to solve from day one.
Jan 29·Tutorial
Implementing an Android TurboModule with Kotlin
Learn how to implement a React Native TurboModule on Android, from the TypeScript spec and Codegen to the Kotlin implementation and package registration.
Jan 19·Tutorial
Working with Different Threads in Swift TurboModules
Learn how JavaScript, native module, background, and main threads interact in React Native TurboModules, and how to use GCD queues to run async work safely in Swift.
Jan 9·Tutorial
How to Add Type-Safe Constants to Swift TurboModules
Learn how to expose typed, immutable constants from a Swift TurboModule using Codegen, and get full end-to-end type safety between native and JavaScript.
Dec 30·Tutorial
Adding Event Emitters to Your TurboModule in Swift
Learn how to emit native events from a Swift TurboModule and subscribe to them in JavaScript, including proper memory management and Codegen integration.
Dec 22·Tutorial
Writing Your First TurboModule in Swift
Learn how to build a fully working TurboModule in Swift, integrate it with Codegen, and bridge it through Objective‑C inside an Expo app.