Back to all posts
React NativeExpoBunMobileJavaScript

Why bunx? Understanding bun add vs. bunx expo install in React Native

October 7, 20264 min read
Why bunx? Understanding bun add vs. bunx expo install in React Native

Why bunx? Understanding bun add vs. bunx expo install in React Native

Recently while setting up a mobile project, I came across an interesting compound command in the installation instructions:

bun add react-native-monnify && bunx expo install react-native-webview

At first glance, it makes you pause. Why are we using bun add for the first package, but switching over to bunx expo install for the second? Why not just bun add both packages and call it a day?

Using bunx in the second command is an intentional choice rooted in how the React Native and Expo ecosystems manage native code compatibility. Here is the complete breakdown of why this pattern exists and why you should follow it.


1. bunx Executes a Tool, bun add Installs a Package

The primary difference comes down to package management versus CLI tool execution:

  • bun add react-native-monnify:
    This command installs the Monnify package directly into your project's node_modules and registers it as a dependency in your package.json.

  • bunx expo install ...:
    bunx is Bun's direct equivalent to npx. It is a package runner. Instead of adding a package to your dependencies, bunx looks for an executable tool—in this case, the Expo CLI—and runs it on the fly without needing a global installation.


2. Why Use expo install Instead of bun add for the WebView?

In an Expo project, you should always use expo install (via bunx) to install core native modules like react-native-webview.

What happens if you run bun add react-native-webview?

If you were to use bun add react-native-webview, Bun would just grab whatever the latest version is available on npm. However, the latest version might not be compatible with your current Expo SDK version, which can lead to runtime crashes or build errors.

Native libraries rely on platform bridges (iOS/Android native code) that are tightly coupled to specific Expo SDK releases.

What happens with bunx expo install react-native-webview?

By running bunx expo install react-native-webview:

  1. bunx calls the Expo CLI tool on demand.
  2. Expo checks your project's current SDK version in package.json and app.json.
  3. Expo automatically selects and installs the exact, compatible version of react-native-webview that matches your project.
  4. Expo uses Bun behind the scenes to perform the fast download and caching.

Summary Comparison

CommandWhat it doesWhy it's used here
bun addInstalls a library directly into node_modules.Used for standard JavaScript/React Native libraries like Monnify that don't require Expo SDK version locking.
bunxRuns a CLI command (Expo) without globally installing it.Used to invoke the Expo smart installer, ensuring native compatibility for the WebView.

Practical Rules of Thumb

When developing React Native apps with Expo and Bun:

  1. For pure JS/TS utilities or standard third-party libraries (e.g., axios, zustand, date-fns):

    bun add <package-name>
    
  2. For native modules and Expo packages (e.g., react-native-webview, expo-camera, expo-location, react-native-reanimated):

    bunx expo install <package-name>
    
  3. To verify compatibility across your dependencies:

    bunx expo doctor
    

    Expo Doctor will scan your project and immediately alert you to any mismatched versions or peer dependency conflicts.


Bonus: What happens if you run expo install on Monnify anyway?

You might wonder: Could I have just run bunx expo install react-native-monnify instead?

Technically, yes, it will still work. When Expo CLI is asked to install a package that is not part of its curated native modules compatibility matrix, it simply falls back to:

bun add react-native-monnify@^latest

However, running bun add directly skips the unnecessary Expo CLI resolution round-trip and keeps the developer mental model clean: use bun add for general JS/TS libraries, and reserve expo install for native modules that require Expo SDK version locking.

Daniel Chukwudubem

Daniel Chukwudubem

Software engineer passionate about building great products.