[英]react-native: Command `run-android` unrecognized. Maybe caused by npm install
最近我開始遇到這個問題,當我在我的項目中安裝一個react-native包(例如: react-navigation
)時,一大堆軟件包都被刪除了(包括我認為的react,react-native)。
然后,當我嘗試運行命令“ 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/>
對這個問題是什么以及如何解決這個問題有任何想法嗎?
在這里找到解決方案。
最初,運行npm install
無效,但隨后刪除package-lock.json
文件並運行npm install
。
之后,我分別安裝了react-navigation
軟件包,並且運行良好。
這是從頭到尾對我有用的。
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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.