簡體   English   中英

react-native:無法識別命令“ run-android”。 可能是因為npm install

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

最近我開始遇到這個問題,當我在我的項目中安裝一個react-native包(例如: react-navigation )時,一大堆軟件包都被刪除了(包括我認為的react,react-native)。

然后,當我嘗試運行命令“ 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步-創建項目。 在此處輸入圖片說明

  • 第2步-運行“ run-android”命令(可行)。 在此處輸入圖片說明

  • 步驟3-將“ react-native-navigation”安裝到項目中。 在此處輸入圖片說明

Notice in the image above. Seems like all the other packages are removed from the project.<br/><br/>
  • 第4步-嘗試再次運行“ run-android”命令。 (將失敗,但之前曾工作過) 在此處輸入圖片說明

對這個問題是什么以及如何解決這個問題有任何想法嗎?

這里找到解決方案。

最初,運行npm install無效,但隨后刪除package-lock.json文件並運行npm install

之后,我分別安裝了react-navigation軟件包,並且運行良好。

這是從頭到尾對我有用的。

  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/ ,以運行示例代碼。

或將其復制到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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM