Gradle fails with Cannot run program "node" (in directory "..."): error=2, No such file or directory

See original GitHub issue

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

gradle stops working (after i clean my project) because it can’t find node for some reason I think it is related to nvm, but can’t confirm it

The thing is, gradle stores somewhere in ~/.gradle the node path or something like that, that is only valid in my actual terminal session. So gradle works fine the first time it runs, but when i open another terminal session it stops working permanently causing the error reported here

:ReactNative:Running '[node, -e, console.log(require('react-native/cli').bin);]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script '/home/luizmarques/Development/sexyfit-app/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 179

* What went wrong:
A problem occurred evaluating script.
> Cannot run program "node" (in directory "/home/luizmarques/Development/sexyfit-app/android"): error=2, No such file or directory

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 6s

React Native version:

System:
    OS: Linux 4.19 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (4) x64 Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz
    Memory: 372.48 MB / 3.84 GB
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 14.16.0 - /tmp/yarn--1616332246373-0.8858334362640385/node
    Yarn: 1.22.5 - /tmp/yarn--1616332246373-0.8858334362640385/yarn
    npm: 6.14.11 - ~/.nvm/versions/node/v14.16.0/bin/npm
    Watchman: Not Found
  SDKs:
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
  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.0 => 0.64.0
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Run any gradlew task the first time
  2. Clean a project
  3. Open another temrinal session
  4. Try running any ./gradlew <task> in react-native-project/android

Expected Results

No errors, since I have node installed

Snack, code example, screenshot, or link to a repository:

Not needed

Only workaround

sudo ln -s "$(which node)" /usr/local/bin/node

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:7
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
dppocommented, Jul 31, 2021

same error on MacBook Air m1

3reactions
cortinicocommented, Jun 21, 2022

I believe the underlying issue is the following: issuetracker.google.com/issues/216364005?pli=1

Closing as this was fixed on Google’s end. The fix is available with Android Studio BumbleBee 2021.1.1 Patch 1.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native on Android: Cannot run program "node": error=2 ...
It's because android studio couldn't find node and should run through ... Gradle sync failed: Cause: error=2, No such file or directory.
Read more >
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 ...
Read more >
Cannot run program "node": error=2, No such file or directory
Hi there,. Hope this message finds you well. I am using SonarQube 6.4 with SonarTS 1.1. I initiate the SonarQube Scanner using a...
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 >
Cannot run program "node": error=2, No such file or directory ...
Cannot build after updating to Bumblebee due to: IOException: Cannot run program "node": error=2, No such file or directory.
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