Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

Gradle cannot run node in a React Native Android build

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

Short 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.

  • Applies to React Native 0.8x, Gradle 8/9, Node.js 22.11+
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 -v
  2. 2Match what you see, then jump to its fix

    1. 1Cannot run program "node": error=2, No such file or directoryGradle's environment has no node on its pathFix
    2. 2Node starts but the bundling step exits with: finished with non-zero exit value 1node is too old for this React Native versionFix
    3. 3The 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

What does the error look like?

  • Cannot run program "node": error=2, No such file or directory
  • Process '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 node

2Fix

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:assembleDebug

Confirmed by reactnative.dev

Did this fix it?

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 -v

2Fix

Install a supported Node version, point nodeExecutableAndArgs at it if needed, and reinstall packages.

node -v
rm -rf node_modules
npm install

3Verify

Run the debug build again.

cd android
./gradlew --stop
./gradlew :app:assembleDebug

Confirmed by reactnative.dev

Did this fix it?

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.json

2Fix

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:assembleDebug

Confirmed by reactnative.dev

Did this fix it?

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:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.