最近,当我安装react-native软件包时,我开始遇到这个问题
(例如:react-navigation
)进入我的项目,一大堆包被删除(包括反应,反应原生,我认为)。
然后当我尝试运行命令" run-android
"时,它说它不会识别。
我最近更新到最新的npm
和react-native-cli
。这是" npm install
"?还是react-native
?
node version: 8.1.2 <br/>
react-native-cli: 2.0.1 <br/>
react-native: 0.45.1 <br/>
react-navigation: 1.0.0-beta.11
以下是重新创建的步骤:
Notice in the image above. Seems like all the other packages are removed from the project.<br/><br/>
对问题是什么以及解决问题的方法有任何想法?
答案 0 :(得分:3)
找到解决方案 here 。
首次运行时npm install
无效,但是,删除package-lock.json
文件并运行npm install
完成了这项工作。
之后我单独安装了react-navigation
包,它运行正常。
答案 1 :(得分:-2)
这是从头到尾对我有用的东西。
react-native init NavTest
(使用此命令在本地安装cli)npm install --save react-navigation
npm install
react-native run android
有点难看,我完全不知道发生了什么,但这很有效。
https://reactnavigation.org/要运行示例代码。或将其复制到index.android.js
import React, { Component } from 'react';
import {
AppRegistry,
Button,
} from 'react-native';
import {
StackNavigator,
} from 'react-navigation';
class HomeScreen extends Component {
static navigationOptions = {
title: 'Welcome',
};
render() {
const { navigate } = this.props.navigation;
return (
<Button
title="Go to Jane's profile"
onPress={() =>
navigate('Profile', { name: 'Jane' })
}
/>
);
}
}
class ProfileScreen extends Component{
static navigationOptions = {
title: 'Jane',
};
render() {
return (null);
}
}
const NavTest= StackNavigator({
Home: { screen: HomeScreen },
Profile: { screen: ProfileScreen },
});
AppRegistry.registerComponent('NavTest', () => NavTest);