Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native on Android: Cannot run program "node": error=2, No such file or directory

EDIT: I am uncertain which steps I took to resolve this problem, and am no longer seeing this error message so I cannot test the solutions below. Please try them individually as different answers seem to be working for different people.

The iOS version works fine, but running Android Studio on my Mac I get the following Gradle Build error (paraphrased):

:ReactNative:Running ‘[node, -e, console.log(require(‘react-native/cli’).bin);]’ command failed.  - Where: Script ‘/Users/…/Desktop/…/node_modules/@react-native-community/cli-platform-android/native_modules.gradle’ line: 154  - What went wrong: A problem occurred evaluating script. > Cannot run program “node”: error=2, No such file or directory  Caused by: java.io.IOException: Cannot run program “node”: error=2, No such file or directory 

I've tried so many things:

  • Following the React Native development set-up: https://reactnative.dev/docs/environment-setup
  • Following this advice about [renaming?] the node path: https://stackoverflow.com/a/54007652
  • Following this advice about symlink: https://stackoverflow.com/a/52779097
  • Ran brew install node. Message: node 14.2.0 is already installed, it’s just not linked. Tried to run brew link --overwrite node, error /usr/local/share/doc/node is not writable.
  • Tried to uninstall and reinstall all the package managers, node, yarn, whatever.

I used to be able to still run yarn android in Terminal, but even that has stopped working.

like image 656
Steve C Avatar asked May 20 '20 20:05

Steve C


1 Answers

It's because android studio couldn't find node and should run through terminal.

If you are using Mac you can run Android studio using This command in terminal

1. Run this open -a /Applications/Android\ Studio.app

2. Then sync Gradle

And this will solve the problem.

like image 177
Aly Avatar answered Oct 04 '22 12:10

Aly