cli: Gradle sync stop working with "Cannot run program "node" message

Environment

System: OS: macOS 11.4 CPU: (8) arm64 Apple M1 Memory: 123.39 MB / 8.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 16.5.0 - /opt/homebrew/bin/node Yarn: 1.22.11 - /opt/homebrew/bin/yarn npm: 7.19.1 - /opt/homebrew/bin/npm Watchman: 4.9.0 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.10.1 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4 Android SDK: API Levels: 29, 31 Build Tools: 29.0.2, 31.0.0 System Images: android-29 | Intel x86 Atom_64, android-31 | Google APIs ARM 64 v8a Android NDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7583922 Xcode: 12.5/12E262 - /usr/bin/xcodebuild Languages: Java: 1.8.0_282 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.1 => 17.0.1 react-native: 0.64.2 => 0.64.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Description

Hey, everyone. Surprisingly for me launching project with android studio stopped to work with gradle sync error. But I still can run project with npx react-native run-android

Caused by: java.io.IOException: Cannot run program "node" (in directory "/Users/zigi/Temp/droidSuck/android"): error=2, No such file or directory
	at java_lang_Runtime$exec$0.call(Unknown Source)
	at ReactNativeModules.getCommandOutput(/Users/zigi/Temp/droidSuck/node_modules/@react-native-community/cli-platform-android/native_modules.gradle:189)
	at ReactNativeModules$getCommandOutput$0.callCurrent(Unknown Source)
	at ReactNativeModules.getReactNativeConfig(/Users/zigi/Temp/droidSuck/node_modules/@react-native-community/cli-platform-android/native_modules.gradle:233)
	at ReactNativeModules$getReactNativeConfig.callCurrent(Unknown Source)
	at ReactNativeModules.<init>(/Users/zigi/Temp/droidSuck/node_modules/@react-native-community/cli-platform-android/native_modules.gradle:84)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at native_modules_btdx1fw5o90mtgvk8m0ztnv6f.run(/Users/zigi/Temp/droidSuck/node_modules/@react-native-community/cli-platform-android/native_modules.gradle:287)
	at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:91)
	... 159 more
Caused by: java.io.IOException: error=2, No such file or directory

I found a workaround - I can launch the android studio from the terminal and error is gone, so my bet it’s doesn’t see node binary from brew folder, but I have no idea why this is happening and why it works before and suddenly stops

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 9
  • Comments: 15 (1 by maintainers)

Most upvoted comments

I am using “Android Studio Bumblebee | 2021.1.1”. it works for me sudo chmod +x /Applications/Android\ Studio.app/Contents/bin/printenv

Also need to restart the Android Studio after the above comment

more info: https://stackoverflow.com/a/70891538/2558451

note: this bug was fixed in Android Studio Bumblebee | 2021.1.1 Patch 1 https://developer.android.com/studio/releases#bumblebee

Hi all, I was able to resolve the issue by updating my Gradle version used. File > Project Structure > Project then under Gradle Version I chose 6.9-rc-1

You can also update it in android/gradle/wrapper/gradle-wrapper.properties file.

Edit: Also in my case, the project I was working on used a very old version of gradle. The above solution above might work on others i.e. symlinks and making sure your node installation is correct.

Still no idea why it’s happening, but was fixed with node symlink sudo ln -s $(which node) /usr/local/bin/node

due https://stackoverflow.com/questions/67337836/new-rn-project-in-m1-mbp-built-failed-could-not-find-node-make-sure-it-is-in

The above solution doesn’t work on my case. I am on chipmunk right now.

Follow this, it worked for me.

For Mac users, use the following command: open -a /Applications/Android\ Studio.app /path/to/my_android_project

For Windows users, use the following command:

start “” “C:\Program Files\Android\Android Studio\bin\studio64.exe” “X:\path\to\my_android_project”

reference https://stackoverflow.com/questions/35363546/open-androidstudio-project-from-command-line-on-osx

I am using “Android Studio Bumblebee | 2021.1.1”. it works for me sudo chmod +x /Applications/Android\ Studio.app/Contents/bin/printenv

more info: https://stackoverflow.com/a/70891538/2558451

Also need to restart the Android Studio after the above comment

I have android studio chipmunk too and the above solution didn’t work for me. My system is apple macbook pro with m1 pro chip.

I don’t think this has anything to do with the version of Android Studio. Try updating to Gradle 6.9 and fix your Node setup: https://benscheer.medium.com/how-to-install-nvm-and-node-on-macos-m1-silicon-in-2022-172fba82d92f