Gradle cannot run node in a React Native Android build
Cannot run program "node": error=2, No such file or directoryShort answer
The React Native Gradle plugin starts node for bundling. If Gradle's environment has no node, you get error=2. Set nodeExecutableAndArgs in the react block of android/app/build.gradle to the full path of node, stop the Gradle daemon, and build again. Check the node version and the cliFile path too.
Fix it fast
1Find out which cause you have
Check that node exists and which version it is, in the same shell or IDE session that starts the build. Then read the real message above the Gradle error.
command -v node node -v2Match what you see, then jump to its fix
- 1
Cannot run program "node": error=2, No such file or directoryGradle's environment has no node on its pathFix - 2
Node starts but the bundling step exits with: finished with non-zero exit value 1node is too old for this React Native versionFix - 3
The bundling step fails in a monorepo or with a node_modules folder outside android/The plugin looks for the CLI or project root in the wrong placeFix
- 1
What does the error look like?
Cannot run program "node": error=2, No such file or directoryProcess 'command 'node'' finished with non-zero exit value 1
Cause 1 of 3
Gradle's environment has no node on its path
1Check
The plugin runs the command in nodeExecutableAndArgs, which is ["node"] by default, so node must be found by name. Compare the result of command -v node with what the build can see.
command -v node2Fix
Give the plugin the full path to node in the react block of android/app/build.gradle (Groovy), using the path printed above.
react {
nodeExecutableAndArgs = ["/usr/local/bin/node"]
}3Verify
Stop running Gradle daemons, then build again.
cd android
./gradlew --stop
./gradlew :app:assembleDebugConfirmed by reactnative.dev
Cause 2 of 3
node is too old for this React Native version
1Check
The React Native setup guide asks for Node 22.11.0 or newer.
node -v2Fix
Install a supported Node version, point nodeExecutableAndArgs at it if needed, and reinstall packages.
node -v
rm -rf node_modules
npm install3Verify
Run the debug build again.
cd android
./gradlew --stop
./gradlew :app:assembleDebugConfirmed by reactnative.dev
Cause 3 of 3
The plugin looks for the CLI or project root in the wrong place
1Check
The defaults are cliFile = ../node_modules/react-native/cli.js and root = .. relative to android/app. Check that these exist.
ls ../node_modules/react-native/cli.js ../package.json2Fix
Set cliFile and root in the react block to the real locations.
react {
root = file("../../")
cliFile = file("../../node_modules/react-native/cli.js")
}3Verify
Build again.
./gradlew :app:assembleDebugConfirmed by reactnative.dev
How do I stop it coming back?
- Keep the Node version in an .nvmrc file or CI config and use the same one on every machine.
- After changing Node or its path, run ./gradlew --stop before the next build.
- Keep the react block of android/app/build.gradle under version control.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Mobile apps
Android build stops at processDebugManifest in a React Native app
Manifest merger failed
processDebugManifest is the step that merges your AndroidManifest.xml with the manifests of every library.
2 causes, each with a fixMobile apps
React Native Android build cannot find the foojay-resolver-convention plugin
Plugin [id: 'org.gradle.toolchains.foojay-resolver-convention'] was not found in any of the following sources:
The foojay plugin is a settings plugin that Gradle downloads from the Plugin Portal.
3 causes, each with a fixMobile apps
Kotlin and Java compile to different JVM targets in a React Native Android build
'compileJava' task (current target is 1.8) and 'compileKotlin' task (current target is 11)
Gradle refuses to build when the Java task and the Kotlin task target different JVM versions.
3 causes, each with a fixMobile apps
The Android emulator opens the app but never connects to Metro or Expo
Metro bundler ECONNREFUSED 127.0.0.1:19001
When the emulator cannot reach Metro, first prove each side on its own: adb sees the emulator, and Metro listens on its port.
4 causes, each with a fixMobile apps
Axios request works on iOS or in a browser but fails on Android with Network Error
AxiosError: Network Error
A React Native app has no CORS, so on Android a Network Error usually means the request never reached the server.
3 causes, each with a fixMobile apps
Axios returns Network Error in a React Native app on iPhone or the iOS Simulator
error.code is ERR_NETWORK and error.response is undefined
A Network Error means iOS stopped the request before any HTTP answer came back.
3 causes, each with a fix