🔧 Error Fixes
· 2 min read
Last updated on

React Native: Metro Bundler Error — Unable to Resolve Module


error: Error: Unable to resolve module

What causes this

Metro bundler can’t find a module you’re importing. Metro is React Native’s JavaScript bundler, and it has a different module resolution system than Node.js or Webpack. Common causes:

  • The package isn’t installed (missing from node_modules)
  • Metro’s cache is stale after installing new packages
  • You’re importing a Node.js-only module that doesn’t work in React Native
  • The package needs native linking that wasn’t completed
  • File path casing issues (common when switching between macOS and Linux)

Fix 1: Clear Metro cache and restart

# React Native CLI
npx react-native start --reset-cache

# Expo
npx expo start --clear

# Or manually clear
rm -rf node_modules/.cache
watchman watch-del-all  # if using watchman

This fixes the issue most of the time. Metro caches aggressively and doesn’t always pick up new packages.

Fix 2: Reinstall dependencies

rm -rf node_modules
npm install
# or
yarn install

# Then restart Metro
npx react-native start --reset-cache

For iOS, also reinstall pods:

cd ios && pod install && cd ..

Fix 3: Check if the package supports React Native

Not all npm packages work in React Native. Node.js built-in modules (fs, path, crypto) don’t exist:

// ❌ Node.js modules don't work in React Native
import fs from 'fs';
import crypto from 'crypto';

// ✅ Use React Native alternatives
import * as FileSystem from 'expo-file-system';
import * as Crypto from 'expo-crypto';

Check the package’s README for React Native compatibility.

Some packages require native linking:

# React Native 0.60+ auto-links, but sometimes you need to manually link
npx react-native link package-name

# For iOS
cd ios && pod install && cd ..

Fix 5: Check metro.config.js

If you need to resolve custom file extensions or module paths:

// metro.config.js
const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname);
config.resolver.sourceExts.push('cjs');
module.exports = config;

How to prevent it

  • Always restart Metro with --reset-cache after installing new packages
  • Check React Native compatibility before adding a package
  • Use Expo’s npx expo install which picks compatible versions automatically
  • Keep a clean metro.config.js and only add custom config when needed

Related: React vs Vue vs Svelte · npm: Cannot Find Module fix · React Hooks cheat sheet