react-native:命令`run-android`无法识别。也许是由npm install引起的

时间:2017-06-19 11:25:29

标签: android react-native npm npm-install react-native-navigation

最近,当我安装react-native软件包时,我开始遇到这个问题 (例如:react-navigation)进入我的项目,一大堆包被删除(包括反应,反应原生,我认为)。

然后当我尝试运行命令" run-android"时,它说它不会识别。

我最近更新到最新的npmreact-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

以下是重新创建的步骤:

  
      
  • 第1步 - 创建项目。   enter image description here

  •   
  • 第2步 - 运行&#34; run-android&#34;命令(这是有效的)。   enter image description here

  •   
  • 第3步 - 安装&#34; react-native-navigation&#34;进入项目。   enter image description here

  •   
Notice in the image above. Seems like all the other packages are removed from the project.<br/><br/>
  
      
  • 第4步 - 尝试运行&#34; run-android&#34;命令再次。 (会失败,但之前曾经工作过)   enter image description here
  •   

对问题是什么以及解决问题的方法有任何想法?

2 个答案:

答案 0 :(得分:3)

找到解决方案 here

首次运行时npm install无效,但是,删除package-lock.json文件并运行npm install完成了这项工作。

之后我单独安装了react-navigation包,它运行正常。

答案 1 :(得分:-2)

这是从头到尾对我有用的东西。

  1. react-native init NavTest (使用此命令在本地安装cli)
  2. 已删除package-lock.json
  3. npm install --save react-navigation
  4. 删除了生成的package-lock.json
  5. npm install
  6. react-native run android 有点难看,我完全不知道发生了什么,但这很有效。 https://reactnavigation.org/要运行示例代码。
  7. 或将其复制到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);