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

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 am very new to coding, and the first time I tried to fix this I broke the iOS version for 4 days. I have already tried (to the best of my abilities):

Following the React Native development set-up: Setting up the development environment · React Native
Following this advice about [renaming?] the node path: java - Android Studio setting node directory for build (Cause: error=2, No such file or directory) - Stack Overflow
Following this advice about symlink: node.js - Jenkins : java.io.IOException: Cannot run program "node": error=2, No such file or directory - Stack Overflow
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.

I am considering uninstalling and reinstalling node, but I am very afraid about destroying things again. Any step-by-step advice would be greatly appreciated, thank you!!

Current mood: Both Donny and Walter

Caveat: I in no way understand why the following works as it does.

The Android app now loads on my emulator, despite the Gradle build error persisting in Android Studio. Here is what happened:

I completely uninstalled node, npm, and yarn, relying heavily on brew and advice online. Note that this step may not be necessary.

I re-installed them using brew. brew install node generated an error: The formula built, but is not symlinked into /usr/local and listed several possible conflicting files.
I manually deleted all listed files. brew install node no longer produced an error

It is possible that I could have simply deleted these files from the beginning to fix the link error, without uninstalling all of those packages.

I also followed this advice to manually set my gradle version to the latest.

Afterwards, running yarn android in your main project folder should work. You can also try brew unlink node && brew link node if you still encounter a link error.

Hopefully this helps and does not lead to more problems, like seeking out the person responsible for urinating on your rug.

1 Like