7

I have been working with react-native project in another pc and it has been working correctly. Now I cloned project to another device where I have react-native installed since I work with other project and I cannot run it.

When I run react-native run-android I get this error:

Cannot run program "npx": error=2, No such file or directory

Edison Biba
  • 4,384
  • 3
  • 17
  • 33
  • What npm version are you using? `npm -v` – MaartenDev Dec 28 '19 at 13:33
  • If you use Ubuntu or Mac OS, please run Android Studio with below command on Terminal. ` $ open -a "Android Studio.app" ` After that, build your react-native android app on the Android Studio. – NinjaDev Aug 06 '20 at 01:45

5 Answers5

9

I'm using Android Studio 4 on Mac OS Catalina 10.15.6. I solved the problem by running Android Studio with bellow command on console.

$ open -a "Android Studio.app"
NinjaDev
  • 1,228
  • 11
  • 21
6

Simple steps you need to go through to make it work with npx

  • sudo npm uninstall -g react-native-cli
  • sudo npm i -g npx
  • npx react-native run-android

More detailed explanation why this is happenig

Issue was that Facebook is not using anymore react-native-cli as they are using npx.

As stated in Facebook page:

If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues.

So i had to run sudo npm uninstall -g react-native-cli to remove react-native-cli

They also say that npx is shipped with nodejs but that wasn't my case.

React Native has a built-in command line interface, which you can use to generate a new project. You can access it without installing anything globally using npx, which ships with Node.js.

So I had to install it using sudo npm i -g npx

After installing npx then just need to run npx react-native run-android.

Be aware of npx before react-native run-android

Now you don't have any command react-native now we only have 'npx' and react-native run-android is just a parameter for npx. For ex. to start metro we should run npx react-native start

Edison Biba
  • 4,384
  • 3
  • 17
  • 33
1

I had the same issues, so I followed these steps:

  1. Start by installing the latest version of Android Studio (Don't delete the old version, just copy paste that to another directory or in my case I just added the Android Studio 3.2.1 that I had to a folder called olderAndroidStudio, on mac).
  2. Make sure you don't click on import settings from Existing.
  3. Follow along the installation, and complete it.
  4. Build and Run, app runs without any problems.

I additionally uninstalled react-native-cli using the method given in the accepted answer.

Kiran
  • 402
  • 1
  • 4
  • 11
0

In my case, I just quit Android Studio and reopened, and the error was gone.

Maybe throw in a ./gradlew clean for goo measure.

James Trickey
  • 1,322
  • 13
  • 21
0

I solved it by finding the command that was throwing error and ran it directly

node -e "console.log(require('react-native/cli').bin)"

which outputs a path, something like

$HOME/my-app/node_modules/@react-native-community/cli/build/bin.js

then I pasted that path in android/app/build.gradle

project.ext.react = [
    entryFile: "index.js",
    enableHermes: true,  // clean and rebuild if changing
    cliPath: "$HOME/my-app/node_modules/@react-native-community/cli/build/bin.js" // <--- add this
]
Dharman
  • 30,962
  • 25
  • 85
  • 135
JJ.
  • 112
  • 2
  • 10