Search code examples
node.jsreact-nativeandroid-studionvm

React Native Build Fails in Android Studio: Node.js Version Not Detected Correctly


Problem

I'm working on a React Native project and recently encountered an issue with building my app in Android Studio. After updating to the newest RN version, I switched to using nvm instead of nodejs to be more flexible with older apps. But somehow I get this error:

java.io.IOException: Cannot run program "node" (in directory "/path/to/my/project"): error=2, No such file or directory

I have installed Node.js v20.11.0 using nvm. Running node -v in the terminal correctly shows v20.11.0.

Environment

  • Operating System: Ubuntu 20.04.6 LTS
  • React Native Version: 0.73.2
  • Android Studio Version: Android Studio Hedgehog | 2023.1.1 Patch 1

This issue persists even after setting the PATH environment variable to include the Node.js binary path in my .bashrc file.

Steps Taken

  1. I have tried reinstalling Node.js using nvm and setting it as the default version.
  2. I have added the Node.js binary path to my PATH variable in .bashrc.
  3. I checked the Node.js version in the terminal within Android Studio, and it shows the correct version.
  4. I have tried modifying Android Studio's VM options to include the correct PATH.

Despite these efforts, the build process in Android Studio still fails to recognize the correct Node.js version.

Question

How can I configure Android Studio to recognize the Node.js version installed via nvm? Are there any specific settings or configurations in Android Studio that I need to adjust to ensure it uses the correct Node.js version during the build process?


Solution

  • Solution

    Ok, as proposed in this threat, creating a symbolic link to the used nvm version fixes thee problem. The issue is that when using nvm, Android Studio does not where to find the node executable.

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