4

最近我开始这个问题,当我安装一个反应本地包 (如:react-navigation)到我的项目,包一大堆的被删除(包括反应,反应母语,我认为) 。react-native:命令`run-android`无法识别。也许通过NPM造成安装

,然后当我尝试运行命令“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步 - 运行“run-android”命令(这工作)。 enter image description here

  • 第3步 - 将“react-native-navigation”安装到项目中。 enter image description here

Notice in the image above. Seems like all the other packages are removed from the project.<br/><br/> 
  • 第4步 - 尝试再次运行 “运行Android” 的命令。 (会失败,但使用前工作) enter image description here

在这个问题上是什么任何想法,任何方式来解决呢?

+0

你有反应,本机安装的CLI? – locropulenton

+0

是@alejandrogarcibles。我用版本信息更新了问题。 –

+0

您是否检查过node_modules中是否有内容被删除? – Raymond

回答

3

实测溶液here

起初运行npm install没有工作,但后来,删除package-lock.json文件和运行npm install做了这项工作。

之后,我分开安装了react-navigation包,它工作正常。

-1

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

  1. react-native init NavTest (CLI是局部用这个命令安装)
  2. 删除包lock.json
  3. npm install --save react-navigation
  4. 删除所生成的包lock.json
  5. npm install
  6. 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);