question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:8
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

63reactions
hexboycommented, Feb 5, 2022

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

8reactions
xgenemcommented, Jun 16, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native on Android: Cannot run program "node": error=2 ...
Solution: · Uninstall Android Studio · Delete all Android variables from bash or zrsh · Install the latest Android studio again ...
Read more >
Different Ways to fix "Error running android: Gradle project ...
Method 2: Sync your project with Gradle files​​ After opening your project click on the Sync Project with Gradle files option. This will ......
Read more >
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". It means that node is not available.
Read more >
Learning the Basics - Gradle User Manual
A build does not need to declare the local Maven repository even if you resolve dependencies ... Gradle does not perform any caching...
Read more >
React Native on Android: Cannot run program "node": error=2 ...
Android : React Native on Android: Cannot run program " node ": error=2, No such file or directory [ Beautify Your Computer ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found