引入react-native-router-flux报找不到@react-navigation/core错误如何解决
修复方案
1. 安装匹配版本的依赖
react-native-router-flux v4.3.1 基于 React Navigation v4 封装,与高版本@react-navigation/core不兼容,你需要安装对应版本的全套路由依赖:
npm install react-navigation@4.4.4 @react-navigation/core@3.7.9 react-navigation-stack@2.10.4 react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view
2. 清理缓存重新编译
依赖安装完成后必须清除所有缓存后重新打包,避免缓存导致的依赖识别异常:
# 清除旧依赖和缓存(可选,推荐执行) rm -rf node_modules package-lock.json npm install # 重置RN打包服务缓存 npx react-native start --reset-cache # 重新编译应用 # Android端执行 npx react-native run-android # iOS端执行 cd ios && pod install && cd ../ npx react-native run-ios
3. 修复代码适配React Native语法
你当前示例代码中使用了Web端的div标签,React Native环境不支持该标签,需要替换为原生View组件:
import React from "react"; import { View } from "react-native"; import { Router, Scene } from "react-native-router-flux"; class Index extends React.Component { render() { return <View /> } } export default Index;
内容的提问来源于stack exchange,提问作者Chilarai
相关产品推荐
相关产品推荐

