React Native "Unable to resolve module": fix the Metro error

Metro shows "Unable to resolve module" when an import points to a file or package it cannot find. Most often the package is not installed, the path or letter case is wrong, or the Metro cache is stale. Check whether the missing name is a package or a relative path, then follow that section.

Last updated

The error

error: Error: Unable to resolve module @react-navigation/native from /app/App.tsx:
@react-navigation/native could not be found within the project or in these directories:
  node_modules

The first name is what the import asked for. The path after "from" is the file with the import.

A package name: install it

If the missing name is a package, it is not in node_modules. Install it, with npx expo install in Expo so the version matches your SDK:

# Expo
npx expo install @react-navigation/native

# React Native CLI
npm install @react-navigation/native

If the package is in package.json but still missing, the install did not finish or was done in another folder. Run your package manager's install in the project root. If the package has native code, rebuild the app afterwards.

A relative path: check the path and letter case

macOS and Windows file systems ignore case by default, so ./components/Button can work on your machine while the file is button.tsx. Linux CI and EAS builds are case-sensitive and fail. Make the import match the file name exactly. If you renamed a file only by case, Git may not have recorded it: use git mv button.tsx Button.tsx.

Clear the Metro cache

After switching branches, installing packages, or moving files, Metro can keep an old module map. Restart it with a clean cache:

# Expo
npx expo start -c

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

Path aliases such as @/components

Metro does not read paths from tsconfig.json by itself. TypeScript then accepts the import while Metro fails at runtime.

  • Expo SDK 50 and later: tsconfig.json paths work out of the box. Restart with npx expo start -c after you change them.
  • React Native CLI: add the same aliases to Babel with babel-plugin-module-resolver, then reset the cache.
// babel.config.js
module.exports = {
  presets: ['module:@react-native/babel-preset'],
  plugins: [
    ['module-resolver', { root: ['./'], alias: { '@': './src' } }],
  ],
};

Monorepos

In a monorepo, the package can be installed in the workspace root while Metro only looks in the app folder. Point Metro at both: add the root to watchFolders and both node_modules folders to resolver.nodeModulesPaths in metro.config.js. Recent Expo SDKs configure this automatically. See React Native not detecting changes for an example config.

Packages that only define "exports"

Some packages expose files only through the exports field in their package.json. Metro reads exports by default from React Native 0.79 (Expo SDK 53). On older versions, a subpath import such as some-lib/server fails to resolve. Upgrade, or set resolver.unstable_enablePackageExports = true in metro.config.js. If the error started right after an upgrade, the opposite can happen: a package now resolves to a different entry point. Check that package's release notes.

Verify the fix

Restart Metro with a clean cache and reload the app. The bundle builds to 100% with no red screen. Run a production export once (npx expo export, or a release build) to catch case-sensitivity problems before CI does.

Still unresolved, or it only fails in CI? Send me the error and I will trace it.

Get help with my bug

Sources