react-native:无法识别命令`运行-android`。可能是由 npm install 引起的
react-native: Command `run-android` unrecognized. Maybe caused by npm install
最近我开始遇到这个问题,当我安装一个 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
以下是重新创建的步骤:
Step 1 - Create project.
Step 2 - Run the "run-android" command (This works).
Step 3 - Install "react-native-navigation" into project.
Notice in the image above. Seems like all the other packages are removed from the project.<br/><br/>
- Step 4 - Try running "run-android" command again. (will fail, but used to work before)
知道问题是什么以及解决问题的方法吗?
找到解决方案 。
起初 运行 npm install
没有用,但是后来,删除 package-lock.json
文件和 运行 npm install
就可以了。
之后我单独安装了 react-navigation
包,它运行良好。
这是从头到尾对我有用的方法。
react-native init NavTest
(cli是用这个命令本地安装的)
- 删除包-lock.json
npm install --save react-navigation
- 删除了生成的包-lock.json
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);
最近我开始遇到这个问题,当我安装一个 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
以下是重新创建的步骤:
Step 1 - Create project.
Step 2 - Run the "run-android" command (This works).
Step 3 - Install "react-native-navigation" into project.
Notice in the image above. Seems like all the other packages are removed from the project.<br/><br/>
- Step 4 - Try running "run-android" command again. (will fail, but used to work before)
知道问题是什么以及解决问题的方法吗?
找到解决方案
起初 运行 npm install
没有用,但是后来,删除 package-lock.json
文件和 运行 npm install
就可以了。
之后我单独安装了 react-navigation
包,它运行良好。
这是从头到尾对我有用的方法。
react-native init NavTest
(cli是用这个命令本地安装的)- 删除包-lock.json
npm install --save react-navigation
- 删除了生成的包-lock.json
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);