简体   繁体   English

每次我安装 react-navigation 我的项目都会停止工作

[英]Everytime I install react-navigation my project stops working

I'm trying to use react-navigation with my react-native project.我正在尝试将 react-navigation 与我的 react-native 项目一起使用。 The project will work up until I install react-navigation.该项目将一直运行,直到我安装 react-navigation。 After I install it when I try to run my app using a virtual device I keep getting an error when I try to use the command react-native run-android.当我尝试使用虚拟设备运行我的应用程序时安装它后,当我尝试使用命令 react-native run-android 时,我不断收到错误消息。

I'm not sure what happened, but it was working just fine before installing react-navigation.我不确定发生了什么,但在安装 react-navigation 之前它工作得很好。 Below is the error I'm getting after I try to start it.以下是我尝试启动后遇到的错误。

react-native start bundler after using react-native run-android使用 react-native run-android 后 react-native 启动打包器

make the following modifications to MainActivity.java:对 MainActivity.java 进行以下修改:

package com.reactnavigation.example;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.ReactRootView;
import com.swmansion.gesturehandler.react.RNGestureHandlerEnabledRootView;

public class MainActivity extends ReactActivity {

  @Override
  protected String getMainComponentName() {
    return "Example";
  }

@Override
 protected ReactActivityDelegate createReactActivityDelegate() {
    return new ReactActivityDelegate(this, getMainComponentName()) {
      @Override
      protected ReactRootView createRootView() {
       return new RNGestureHandlerEnabledRootView(MainActivity.this);
      }
    };
  }
}

Then add the following at the top of your entry file, such as index.js or App.js:然后在入口文件的顶部添加以下内容,例如 index.js 或 App.js:

import 'react-native-gesture-handler';

https://reactnavigation.org/docs/en/getting-started.html https://reactnavigation.org/docs/en/getting-started.html

Judging by the "EPERM" this error is telling you that you do not have the rights to do the operation.从“EPERM”判断这个错误告诉你你没有执行操作的权利。 If you have followed the guide on the documentation page and have verified that you have added the lines from the answer written by Anish (to which I edited out the "+" from the lines of code) then you should be able to use the dependency.如果您已按照文档页面上的指南进行操作并确认您已添加了Anish所写答案中的行(我从代码行中删除了“+”),那么您应该能够使用依赖项. If the error still shows up, check where you created the project (check that you have the priviledges to write to that folder) and check your code.如果错误仍然出现,请检查您创建项目的位置(检查您是否具有写入该文件夹的权限)并检查您的代码。 I would like to point out that in the latest version, react navigation has spilt its dependencies in multiple packages (for example there's one for the stack navigator, one for the tab navigator and so on).我想指出的是,在最新版本中,react navigation 已经将其依赖项溢出到多个包中(例如,一个用于堆栈导航器,一个用于选项卡导航器等等)。 Also be sure to install the packages named react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context .还要确保安装名为react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context

You should also try to use npm cache clean --force to clean the cache and npm install -g npm@latest --force to install the latest npm globally as administrator.您还应该尝试使用npm cache clean --force来清理缓存,并使用npm install -g npm@latest --force以管理员身份全局安装最新的 npm。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM