react-native: Command `run-android` unrecognized. Maybe caused by npm install

后端 未结 2 1858
北恋
北恋 2021-01-05 06:09

Recently I started getting this issue, when I install a react-native package (eg: react-navigation) into my project, a whole bunch of packages are been removed

相关标签:
2条回答
  • 2021-01-05 06:38

    Here's what worked for me from start to finish.

    1. react-native init NavTest (The cli is locally installed with this command)
    2. deleted package-lock.json
    3. npm install --save react-navigation
    4. deleted the generated package-lock.json
    5. npm install
    6. react-native run android A little ugly, I don't know entirely what happened, but this worked. https://reactnavigation.org/ for sample code to run.

    Or Copy this to 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);
    
    0 讨论(0)
  • 2021-01-05 06:45

    Found the solution here.

    At first running npm install didn't work, but then, deleting the package-lock.json file and running npm install did the job.

    After that I installed react-navigation package seperately and it worked fine.

    0 讨论(0)
提交回复
热议问题