You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Navigation安装报错求助:@react-navigation/native模块未找到问题解决方案咨询

Fixing "@react-navigation/native could not be found" Error in React Native

Hey there, I’ve dealt with this exact frustration when setting up React Navigation as a beginner too—let’s get this sorted out step by step:

Step 1: Verify & Reinstall the Core Dependency

First, double-check that the @react-navigation/native package is actually installed in your project. Sometimes installs fail silently due to network issues or permission problems.

Run the appropriate command for your package manager:

  • For npm:
    npm install @react-navigation/native
    
  • For yarn:
    yarn add @react-navigation/native
    

After running this, check your project’s package.json file—you should see @react-navigation/native listed under the dependencies section. If it’s not there, the install didn’t complete successfully, so try running the command again and watch the terminal for any error messages.

Step 2: Clear Caches (This Fixes Most "Missing Package" Issues)

React Native and package managers can hold onto stale cache that causes weird errors like this. Clear all relevant caches:

  1. Clear your package manager cache:
    • npm:
      npm cache clean --force
      
    • yarn:
      yarn cache clean
      
  2. Reset the Metro bundler cache:
    npx react-native start --reset-cache
    
  3. For iOS projects, update and reinstall pods:
    cd ios && pod install --repo-update && cd ..
    
  4. For Android projects, clean the build cache:
    cd android && ./gradlew clean && cd ..
    

Step 3: Check for Import Typos

Make sure you’re importing from the correct package in your code. A tiny typo (like missing a hyphen or misspelling "navigation") can cause this error. Your import should look like this:

import { NavigationContainer } from '@react-navigation/native';

Step 4: Ensure Required Peer Dependencies Are Installed

React Navigation needs additional peer dependencies to work. If you’re using a bare React Native project, install these:

npm install react-native-screens react-native-safe-area-context

If you’re using Expo, use this command instead:

npx expo install react-native-screens react-native-safe-area-context

Step 5: Restart Everything

Sometimes the simplest fix is to restart your entire development setup:

  • Close your Metro bundler terminal window
  • Quit and restart your simulator/physical device
  • Open a new terminal, navigate to your project, and run npx react-native run-ios or npx react-native run-android again

9 times out of 10, combining steps 1-5 will resolve this error. If you still run into issues, check the terminal output for any specific error messages during installation—those will give you clues about what’s going wrong.

内容的提问来源于stack exchange,提问作者MOHAMMAD SIDDIQUE

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.01 00:47:34