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

React Native版本不匹配错误:执行npm run android时遇问题求助

Fixing React Native Version Mismatch Error with npm run android

Hey there, let's work through this version mismatch error you're hitting when trying to run your React Native app on Android. I've run into similar hiccups with Expo/Crna setups before, so here are some actionable steps to resolve it:

Step 1: Wipe Caches and Reinstall Dependencies Fresh

Old cached files are the most common culprit here. Let's start with a clean slate:

  • Delete your node_modules folder completely:
    # Mac/Linux
    rm -rf node_modules
    # Windows (Command Prompt)
    rd /s /q node_modules
    
  • Clear npm's cached packages to avoid stale installs:
    npm cache clean --force
    
  • Reinstall all dependencies:
    npm install
    
  • Reset the Metro Bundler cache to ensure it picks up the correct versions:
    react-native-scripts start --reset-cache
    
    Once the bundler is running, try launching Android again with npm run android.

Step 2: Verify Node/NPM Version Compatibility

Your current Node v8.9.4 is technically supported for React Native 0.50.3, but npm v4.6.1 can have compatibility issues with newer package structures. Try upgrading npm to a more stable version for Node 8:

npm install -g npm@5.6.0

Alternatively, switch to the latest LTS release of Node 8 (which has better stability):

nvm install 8.17.0
nvm use 8.17.0
npm install

Step 3: Check for Background Bundler Processes

Sometimes old Metro Bundler instances stick around in the background and serve outdated code. Close all terminal windows running your app, then open a fresh terminal and run:

npm run android

This ensures you're starting with a completely new bundler session.

Step 4: If You've Ejected, Clean Android Gradle Cache

If you've run npm run eject to get access to the native Android project, the Gradle cache might be holding onto old React Native versions:

  • Navigate to the Android directory:
    cd android
    
  • Clean the Gradle build cache:
    # Mac/Linux
    ./gradlew clean
    # Windows
    gradlew clean
    
  • Go back to your project root and re-run the Android command:
    cd ..
    npm run android
    

Quick Validation Check

Before trying the above steps, double-check that your installed React Native version matches your package.json:

npm list react-native

You should see react-native@0.50.3 listed—if not, the reinstall step will fix this.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.15 04:30:08