Install Expo modules in an existing React Native project (2024)

Learn how to prepare your existing React Native project to install and use any Expo module.

To use Expo modules in your app, you will need to install and configure the expo package.

The expo package has a small footprint; it includes only a minimal set of packages that are needed in nearly every app and the module and autolinking infrastructure that other Expo SDK packages are built with. Once the expo package is installed and configured in your project, you can use npx expo install to add any other Expo module from the SDK.

Depending on how you initialized the project, there are two ways you can install the Expo modules: automatically or manually.

Automatic installation

To install and use Expo modules, the easiest way to get up and running is with the install-expo-modules command.

Terminal

# Install and configure the expo package automatically

-

npx install-expo-modules@latest

  • When the command succeeds, you will be able to add any Expo module in yourapp! Proceed to Usage for more information.

  • If the command fails, please follow the manual installation instructions.Updating code programmatically can be tricky, and if your project deviates significantly from adefault React Native project, then you need to perform manual installation and adapt theinstructions here to your codebase.

Manual installation

The following instructions apply to installing the latest version of Expo modules in React Native 0.74.

Terminal

-

npm install expo

Once installation is complete, apply the changes from the following diffs to configure Expo modules in your project. This is expected to take about five minutes, and you may need to adapt it slightly depending on how customized your project is.

Configuration for Android

Configuration for iOS

Optionally, you can also add additional delegate methods to your AppDelegate.mm. Some libraries may require them, so unless you have a good reason to leave them out, it is recommended to add them. See delegate methods in AppDelegate.mm.

Save all of your changes. In Xcode, update the iOS Deployment Target under Target → Build Settings → Deployment to iOS 13.4. The last step is to install the project's CocoaPods again to pull in Expo modules that are detected by use_expo_modules! directive that we added to the Podfile:

Terminal

# Install pods

-

npx pod-install

# Alternatively, the run command will install them for you

-

npx expo run:ios

Configure Expo CLI for bundling on Android and iOS

We recommend using Expo CLI to bundle your app JavaScript code and assets. This adds support for using the "main" field in package.json supports Expo Router. Not using Expo CLI for bundling may result in unexpected behavior. Learn more about Expo CLI.

Extend expo/metro-config in your metro.config.js
Configure Android project to bundle with Expo CLI
Configure iOS project to bundle with Expo CLI

Replace the shell script in the "Bundle React Native code and images" phase under the "Build Phases" tab for your target in Xcode with the following:

if [[ -f "$PODS_ROOT/../.xcode.env" ]]; then source "$PODS_ROOT/../.xcode.env"fiif [[ -f "$PODS_ROOT/../.xcode.env.local" ]]; then source "$PODS_ROOT/../.xcode.env.local"fi# The project root by default is one level up from the ios directoryexport PROJECT_ROOT="$PROJECT_DIR"/..if [[ "$CONFIGURATION" = *Debug* ]]; then export SKIP_BUNDLING=1fiif [[ -z "$ENTRY_FILE" ]]; then # Set the entry JS file using the bundler's entry resolution. export ENTRY_FILE="$("$NODE_BINARY" -e "require('expo/scripts/resolveAppEntry')" "$PROJECT_ROOT" ios relative | tail -n 1)"fiif [[ -z "$CLI_PATH" ]]; then # Use Expo CLI export CLI_PATH="$("$NODE_BINARY" --print "require.resolve('@expo/cli')")"fiif [[ -z "$BUNDLE_COMMAND" ]]; then # Default Expo CLI command for bundling export BUNDLE_COMMAND="export:embed"fi`"$NODE_BINARY" --print "require('path').dirname(require.resolve('react-native/package.json')) + '/scripts/react-native-xcode.sh'"`

And add support the "main" field in package.json by making the following change to AppDelegate.mm:

 - (NSURL *)getBundleURL { #if DEBUG- return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"];+ return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@".expo/.virtual-metro-entry"]; #else  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; #endif

Usage

Verifying installation

You can verify that the installation was successful by logging a value from expo-constants.

  • Run npx expo install expo-constants
  • Then, run npx expo run and modify your app JavaScript code to add the following:
import Constants from 'expo-constants';console.log(Constants.systemFonts);

Using Expo SDK packages

Once the expo package is installed and configured in your project, you can use npx expo install to add any other Expo module from the SDK. See Using Libraries for more information.

Expo modules included in the expo package

The following Expo modules are brought in as dependencies of the expo package:

  • expo-application - Generates the installation id in remote logging in development. This module is optional and can be safely removed if you do not use expo-dev-client.
  • expo-asset - A JavaScript-only package that builds around expo-file-system and provides a common foundation for assets across all Expo modules.
  • expo-constants - Provides access to the manifest.
  • expo-file-system - Interact with the device file system. Used by expo-asset and many other Expo modules. Commonly used directly by developers in application code.
  • expo-font - Load fonts at runtime. This module is optional and can be safely removed, however; it is recommended if you use expo-dev-client for development and it is required by @expo/vector-icons.
  • expo-keep-awake - Prevents your device from going to sleep while developing your app. This module is optional and can be safely removed.

To exclude any of these modules, refer to the following guide on excluding modules from autolinking.

Excluding specific modules from autolinking

If you need to exclude Expo modules that you are not using but they got installed by other dependencies, you can use the expo.autolinking field in package.json:

package.json

{ "name": "...", "dependencies": {}, "expo": { "autolinking": { "exclude": ["expo-keep-awake"] } }}

You can also exclude a specific platform by using exclude under the platform key:

package.json

{ "name": "...", "dependencies": {}, "expo": { "autolinking": { "exclude": ["expo-font"], "ios": { "exclude": ["expo-keep-awake"] } } }}
Install Expo modules in an existing React Native project (2024)

FAQs

How do I install Expo module in React Native? ›

To install and use Expo modules, the easiest way to get up and running is with the install-expo-modules command. When the command succeeds, you will be able to add any Expo module in your app! Proceed to Usage for more information. If the command fails, please follow the manual installation instructions.

How do I use Expo in existing React Native project? ›

Next Steps
  1. Install Expo modules. If you have already initialized a React Native app without create-expo-app , learn how to install the Expo module library.
  2. Use Expo SDK. ...
  3. Write native modules. ...
  4. Use Expo CLI. ...
  5. Native project upgrade helper. ...
  6. Adopt Prebuild. ...
  7. App distribution.
Jul 1, 2024

Can I use expo package in React Native? ›

Yes! All Expo tools and services work great in any React Native app. For example, you can use any part of the Expo SDK, expo-dev-client and EAS Build, Submit, and Update — they work great! Learn more about installing expo in your project, adopting prebuild, and setting up EAS Build.

How to use a standalone expo module in your project? ›

You can publish the module on npm and then add it to your project by installing it as a dependency.
  1. Initialize a new module. Start by creating a new module using create-expo-module . ...
  2. Run the example project. Run the example project to make sure everything is working. ...
  3. Publish the package to npm. ...
  4. Test the published module.

How do I upgrade Expo in React Native project? ›

Upgrading your Expo project to a new version of React Native requires updating the react-native , react , and expo package versions in your package.json file. Expo recommends upgrading SDK versions incrementally, one at a time. Doing so will help you pinpoint breakages and issues that arise during the upgrade process.

Can you mix React Native and Expo? ›

Expo projects can use both third-party React Native libraries with native code and your own custom native code. Creating a development build allows you to include your specific native dependencies and customizations and not only what comes with the latest Expo SDK.

How do you initialize Expo in React Native? ›

How to use Expo with React Native
  1. npm install expo-cli --global. You are ready to create your first project. Use the Expo command to initialize a new project on the command line. ...
  2. expo init myReactNativeProject. Afterward, navigate into your project and start it:
  3. cd myReactNativeProject. expo start.
Aug 5, 2020

Is expo better than React Native? ›

If you are just getting started with app development or need a simplified process, Expo can be a great choice. However, if you require more control and customization options, React Native CLI might be the better fit.

Should I use expo install or npm install? ›

Installing a third-party library

We recommend always using npx expo install instead of npm install or yarn add directly because it allows Expo CLI to pick a compatible version of a library when possible and also warn you about known incompatibilities.

How do I deploy React Native app with Expo? ›

  1. Login to your expo account from the project terminal. ...
  2. Install eas-cli globally. ...
  3. Login or sign up to your expo account.
  4. Create an organization from expo account.
  5. Create a new project at expo from the project tab.
  6. Copy the ID from the project you created.
  7. Initiate the project Id at your expo project using project terminal b.
Mar 23, 2024

Can you run React Native without Expo? ›

We believe that the best way to experience React Native is through a Framework, a toolbox with all the necessary APIs to let you build production ready apps. You can also use React Native without a Framework, however we've found that most developers benefit from using a React Native Framework like Expo.

How do I install Expo in an existing project? ›

Install Expo Router
  1. We recommend creating a new Expo app using create-expo-app to create a project with Expo Router library already installed and configured: - npx create-expo-app@latest.
  2. Now, you can start your project by running: - npx expo start. ...
  3. Modify project configuration. ...
  4. Clear bundler cache.
Jul 10, 2024

Can I use Expo in production? ›

By default, running your project locally with npx expo start runs it in development mode, whereas a published project (with eas update ), or any standalone app, will run in production mode. Development mode includes useful warnings and gives you access to tools that make development and debugging easier.

What is bridge in React Native? ›

React Native is combined with iOS and Android. We can create a React Native bridge between the Native languages like Java, Kotlin, Objective-c, Swift, and JavaScript code. Here bridge means the communication between the native platform and React Native.

How do I import Expo font into React Native? ›

For bare React Native projects, you must ensure that you have installed and configured the expo package before continuing.
  1. Add the package to your npm dependencies. npx expo install expo-font.
  2. Configure for iOS. Run npx pod-install after installing the npm package.
  3. Configure for Android. No additional set up necessary.
Jul 16, 2024

How do I deploy React Native app to Expo? ›

  1. Login to your expo account from the project terminal. ...
  2. Install eas-cli globally. ...
  3. Login or sign up to your expo account.
  4. Create an organization from expo account.
  5. Create a new project at expo from the project tab.
  6. Copy the ID from the project you created.
  7. Initiate the project Id at your expo project using project terminal b.
Mar 23, 2024

What is expo for React Native? ›

Expo is a production-grade React Native Framework. Expo provides developer tooling that makes developing apps easier, such as file-based routing, a standard library of native modules, and much more. Expo's Framework is free and open source, with an active community on GitHub and Discord.

References

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Duncan Muller

Last Updated:

Views: 6197

Rating: 4.9 / 5 (59 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Duncan Muller

Birthday: 1997-01-13

Address: Apt. 505 914 Phillip Crossroad, O'Konborough, NV 62411

Phone: +8555305800947

Job: Construction Agent

Hobby: Shopping, Table tennis, Snowboarding, Rafting, Motor sports, Homebrewing, Taxidermy

Introduction: My name is Duncan Muller, I am a enchanting, good, gentle, modern, tasty, nice, elegant person who loves writing and wants to share my knowledge and understanding with you.