这是我得到的错误:
的package.json
{
"name": "LoginApp2",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"react": "16.0.0-alpha.12",
"react-native": "0.48.3"
},
"devDependencies": {
"babel-jest": "21.2.0",
"babel-preset-react-native": "4.0.0",
"jest": "21.2.1",
"react-test-renderer": "16.0.0-alpha.12"
},
"jest": {
"preset": "react-native"
}
}
index.js
import React, { Component } from 'react';
import { AppRegistry,View,Text,StyleSheet } from 'react-native';
import UsersManager from './pages/app';
AppRegistry.registerComponent('LoginApp2', () => UsersManager);
信息页/ app.js
import React, { Component } from 'react';
import { AppRegistry,View,Text,StyleSheet,ScrollView,TouchableOpacity } from 'react-native';
import { StackNavigator } from 'react-navigation';
import HomeScreen from './home';
import Login from './login';
import Register from './register';
import Profile from './profile';
const UsersManager = StackNavigator({
Home: { screen: HomeScreen },
Login: { screen: Login },
Register: {screen: Register},
Profile: {screen: Profile}
});
export default UsersManager;
有人可以帮我解决这个问题吗?
答案 0 :(得分:7)
此错误表示您尚未安装react-navigation
模块或已安装模块但未使用react-native run-android
或react-native run-ios
重新构建项目。< / p>
遵循这些步骤可以解决您的问题:
react-navigation
模块。react-native start
再次启动打包程序。答案 1 :(得分:5)
日期:2020年6月25日工作:
执行以下步骤:
安装React导航 npm install react-navigation
安装依赖项 expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-安全区域上下文@ react-native-community / masked-view
安装React导航堆栈 npm install react-navigation-stack @ react-native-community / masked-view
启动应用并使用以下命令清除缓存 npm start -c
答案 2 :(得分:4)
我们需要安装以下依赖项:
npm i react-navigation @react-native-community/masked-view react-native-gesture-handler react-native-reanimated react-native-safe-area-context react-native-screens
在代码中导入以下内容:
import {createAppContainer} from 'react-navigation';
import {createStackNavigator} from 'react-navigation-stack';
答案 3 :(得分:3)
您只需要安装缺少的模块即可。
npm install react-navigation
然后重新启动
npm start
答案 4 :(得分:0)
我刚刚开始学习反应。遇到了这个问题,尝试了互联网上的所有内容-没有任何效果。使用Yarn代替npm会有所帮助!
答案 5 :(得分:0)
install
已替换为add
以添加新的依赖项。改为运行yarn add react-navigation
。
答案 6 :(得分:0)
此错误发生在更新到新版本后,要修复它,只需运行以下命令
npx react-native start --reset-cache