volta icon indicating copy to clipboard operation
volta copied to clipboard

Node is not available in React Native

Open c0d3x opened this issue 1 year ago • 12 comments

Setup: Mac OS 12.6 running on Apple M1 Max chip. Terminal: iTerm 2 with ZSH

When developing react-native apps, and I run ./gradlew clean in /MyProject/android/ folder, I get this message. Or when I try to start ios with npm run ios, the terminal that pops up also is unable to start metro because volta is missing a default node ref.

Volta error: Node is not available. To run any Node command, first set a default version using `volta install node`Error details written to /Users/user/.volta/log/volta-error-2022-10-18_10_19_44.823.log

The log file contains this info:

"node" "-e" "try {console.log(require(\'@react-native-community/cli\').bin);} catch (e) {console.log(require(\'react-native/cli\').bin);}"
Volta v1.0.8

Node is not available.

To run any Node command, first set a default version using `volta install node`

Error cause: Resource temporarily unavailable (os error 35)

Running volta list in same folder (/MyProject/android/) I get this:

Currently active tools:

    Node: v16.17.0 (current @ /Users/user/MyProject/package.json)
    npm: v8.19.2 (current @ /Users/user/MyProject/package.json)
    Yarn: v1.22.19 (default)
    Tool binaries available: NONE

See options for more detailed reports by running `volta list --help`.

Content within platform.json

{
  "node": {
    "runtime": "16.17.0",
    "npm": "8.19.2"
  },
  "yarn": "1.22.19"
}

.zshrc config:

export VOLTA_HOME=$HOME/.volta
export PATH=$PATH:$VOLTA_HOME/bin

PATH output

$ echo $PATH | tr ":" "\n"

/Users/user/.pyenv/shims
/Users/user/.jenv/shims
/Users/user/.rbenv/shims
/opt/homebrew/bin
/opt/homebrew/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/Library/Apple/usr/bin
/Users/user/Library/Application Support/JetBrains/Toolbox/scripts
/usr/local/opt/ncurses/bin
/Users/user/Library/Android/sdk/emulator
/Users/user/Library/Android/sdk/tools
/Users/user/Library/Android/sdk/tools/bin
/Users/user/Library/Android/sdk/platform-tools
/Users/user/.fastlane/bin
/Users/user/.volta/bin
/Users/user/.gem/bin
/Users/user/.rbenv/bin
/Users/user/.jenv/bin

Volta path:

$ which volta
/opt/homebrew/bin/volta

Node path:

$ which node
/usr/local/bin/node

$ la /usr/local/bin/
node -> /Users/user/.volta/bin/node

$ la ~/.volta/bin
node -> /opt/homebrew/Cellar/volta/1.0.8/bin/volta-shim
npm -> /opt/homebrew/Cellar/volta/1.0.8/bin/volta-shim
npx -> /opt/homebrew/Cellar/volta/1.0.8/bin/volta-shim
yarn -> /opt/homebrew/Cellar/volta/1.0.8/bin/volta-shim

What is the problem here? How can I resolve this?

c0d3x avatar Oct 18 '22 08:10 c0d3x

Hi @c0d3x, this is something we've seen, but haven't been able to reliably reproduce every time. See #1007 for more discussion. For some reason, when React Native starts its shell, changing something that causes Volta to look in the wrong place for platform information.

Within the terminal spawned by npm run ios, can you share what $HOME and $VOLTA_HOME are set to, if anything? Also, what does cwd output, is that different from the project directory?

charlespierce avatar Oct 18 '22 17:10 charlespierce

Encountered on an initially setup macOS 12.6.1

Environment

env
$ env
TERM_PROGRAM=Apple_Terminal
ANDROID_HOME=/Users/longxiang/Library/Android/Sdk
TERM=xterm-256color
SHELL=/bin/zsh
TMPDIR=/var/folders/h0/3cqyncj14c7bk4k5xq77q45r0000gn/T/
TERM_PROGRAM_VERSION=445
VOLTA_HOME=/Users/longxiang/.volta
OLDPWD=/Users/longxiang/Desktop
TERM_SESSION_ID=6F8F7191-3560-4407-B385-1CDB379C0ED4
USER=longxiang
SSH_AUTH_SOCK=/private/tmp/com.apple.launchd.bmeObBDSUm/Listeners
PATH=/Users/longxiang/.volta/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin
__CFBundleIdentifier=com.apple.Terminal
PWD=/Users/longxiang
LANG=zh_CN.UTF-8
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
HOME=/Users/longxiang
SHLVL=1
LOGNAME=longxiang
_=/usr/bin/env
volta ls
$ volta ls
⚡️ Currently active tools:

    Node: v16.18.1 (default)
    Yarn: v1.22.19 (default)
    Tool binaries available: NONE

See options for more detailed reports by running `volta list --help`.
cat ~/.zshrc
$ cat ~/.zshrc
########################
# Profile for /bin/zsh #
########################

# Volta & Node
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"

# Java & Android
export ANDROID_HOME=~/Library/Android/Sdk
alias adb=$ANDROID_HOME/platform-tools/adb
cat ~/.bash_profile
$ cat ~/.bash_profile
#########################
# Profile for /bin/bash #
#########################

# Volta & Node
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
cat ~/.profile
$ cat ~/.profile 
#######################
# Profile for /bin/sh #
#######################

# Volta & Node
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
brew list
$ brew list
==> Formulae
cocoapods		pcre			the_silver_searcher	xz
java -version
$ java -version
openjdk version "11.0.17" 2022-10-18 LTS
OpenJDK Runtime Environment Zulu11.60+19-CA (build 11.0.17+8-LTS)
OpenJDK 64-Bit Server VM Zulu11.60+19-CA (build 11.0.17+8-LTS, mixed mode)
xcodebuild -version
$ xcodebuild -version
Xcode 14.0
Build version 14A309

Reproduce

Setup mylib

  • npx create-react-native-library mylib
$ npx create-react-native-library --version
0.27.0
$ npx create-react-native-library mylib
✔ What is the name of the npm package? … react-native-mylib
✔ What is the description for the package? … mylib
✔ What is the name of package author? … Sunbreak
✔ What is the email address for the package author? … [email protected]
✔ What is the URL for the package author? … https://github.com/Sunbreak
✔ What is the URL for the repository? … https://github.com/Sunbreak/react-native-mylib
✔ What type of library do you want to develop? › Native module
? Which languages do you want to use? › - Use arrow-keys. Return to submit.
❯   Java & Objective-C
    Kotlin & Objective-C
    Java & Swift
    Kotlin & Swift
    C++ for Android & iOS
  • cd mylib && yarn
$ cd mylib && yarn
yarn run v1.22.19
$ yarn example && yarn install && yarn example pods
$ yarn --cwd example
info No lockfile found.
[1/4] 🔍  Resolving packages...
warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
warning react-native > @react-native-community/cli > @react-native-community/cli-plugin-metro > metro > metro-minify-uglify > [email protected]: support for ECMAScript is superseded by `uglify-js` as of v3.13.0
warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > [email protected]: https://github.com/lydell/resolve-url#deprecated
warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > [email protected]: Please see https://github.com/lydell/urix#deprecated
warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > [email protected]: See https://github.com/lydell/source-map-url#deprecated
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "react-native > react-native-codegen > [email protected]" has unmet peer dependency "@babel/preset-env@^7.1.6".
[4/4] 🔨  Building fresh packages...

success Saved lockfile.
info No lockfile found.
[1/4] 🔍  Resolving packages...
warning @arkweid/[email protected]: @arkweid/lefthook has been renamed to @evilmartians/lefthook, please upgrade to it. You also can use @evilmartians/lefthook-installer
warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > [email protected]: See https://github.com/lydell/source-map-resolve#deprecated
warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > [email protected]: See https://github.com/lydell/source-map-url#deprecated
warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > [email protected]: Please see https://github.com/lydell/urix#deprecated
warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > [email protected]: https://github.com/lydell/resolve-url#deprecated
warning react-native > @react-native-community/cli > @react-native-community/cli-plugin-metro > metro > metro-minify-uglify > [email protected]: support for ECMAScript is superseded by `uglify-js` as of v3.13.0
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
warning "react-native > [email protected]" has unmet peer dependency "@babel/core@*".
warning "react-native > react-native-codegen > [email protected]" has unmet peer dependency "@babel/preset-env@^7.1.6".
[4/4] 🔨  Building fresh packages...
success Saved lockfile.
$ bob build
ℹ Building target commonjs
ℹ Cleaning up previous build at lib/commonjs
ℹ Compiling 1 files in src with babel
✔ Wrote files to lib/commonjs
ℹ Building target module
ℹ Cleaning up previous build at lib/module
ℹ Compiling 1 files in src with babel
✔ Wrote files to lib/module
ℹ Building target typescript
ℹ Cleaning up previous build at lib/typescript
ℹ Generating type definitions with tsc
✔ Wrote definition files to lib/typescript
$ yarn --cwd example pods
$ pod-install --quiet
1.11.3
> pod install
Auto-linking React Native module for target `MylibExample`: react-native-mylib
[Codegen] Generating ./build/generated/ios/React-Codegen.podspec.json
Analyzing dependencies
Fetching podspec for `DoubleConversion` from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`
[Codegen] Found FBReactNativeSpec
Fetching podspec for `RCT-Folly` from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`
Fetching podspec for `boost` from `../node_modules/react-native/third-party-podspecs/boost.podspec`
Fetching podspec for `glog` from `../node_modules/react-native/third-party-podspecs/glog.podspec`
Fetching podspec for `hermes-engine` from `../node_modules/react-native/sdks/hermes/hermes-engine.podspec`
Downloading dependencies
Installing CocoaAsyncSocket (7.6.5)
Installing DoubleConversion (1.1.6)
Installing FBLazyVector (0.70.6)
Installing FBReactNativeSpec (0.70.6)
Installing Flipper (0.125.0)
Installing Flipper-Boost-iOSX (1.76.0.1.11)
Installing Flipper-DoubleConversion (3.2.0.1)
Installing Flipper-Fmt (7.1.7)
Installing Flipper-Folly (2.6.10)
Installing Flipper-Glog (0.5.0.5)
Installing Flipper-PeerTalk (0.0.4)
Installing Flipper-RSocket (1.4.3)
Installing FlipperKit (0.125.0)
Installing OpenSSL-Universal (1.1.1100)
Installing RCT-Folly (2021.07.22.00)
Installing RCTRequired (0.70.6)
Installing RCTTypeSafety (0.70.6)
Installing React (0.70.6)
Installing React-Codegen (0.70.6)
Installing React-Core (0.70.6)
Installing React-CoreModules (0.70.6)
Installing React-RCTActionSheet (0.70.6)
Installing React-RCTAnimation (0.70.6)
Installing React-RCTBlob (0.70.6)
Installing React-RCTImage (0.70.6)
Installing React-RCTLinking (0.70.6)
Installing React-RCTNetwork (0.70.6)
Installing React-RCTSettings (0.70.6)
  • yarn example android
$ yarn example android    
yarn run v1.22.19
$ yarn --cwd example android
$ react-native run-android
info Starting JS server...
info Installing the app...

> Task :app:installDebug
Installing APK 'app-debug.apk' on 'Pixel 4 - 13' for :app:debug
Installed on 1 device.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 15s
55 actionable tasks: 2 executed, 53 up-to-date
info Connecting to the development server...
info Starting the app on "9A261FFAZ0040M"...
Starting: Intent { cmp=com.mylibexample/.MainActivity }
✨  Done in 17.63s.

Run Android build

  • STOP yarn example android
  • cd example/android
  • ./gradlew failed while ./gradlew --no-daemon work
$ ./gradlew
:ReactNative:Unexpected empty result of running '[node, -e, try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}]' command.
:ReactNative:Running '[node, -e, try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script '/Users/longxiang/mylib/example/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 413

* What went wrong:
A problem occurred evaluating script.
> Volta error: Node is not available.To run any Node command, first set a default version using `volta install node`Error details written to /Users/longxiang/.volta/log/volta-error-2022-11-19_15_48_25.370.log

* 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 25s
$ ./gradlew --no-daemon
To honour the JVM settings for this build a single-use Daemon process will be forked. See https://docs.gradle.org/7.5.1/userguide/gradle_daemon.html#sec:disabling_the_daemon.
Daemon will be stopped at the end of the build 

> Task :help

Welcome to Gradle 7.5.1.

To run a build, run gradlew <task> ...

To see a list of available tasks, run gradlew tasks

To see more detail about a task, run gradlew help --task <task>

To see a list of command-line options, run gradlew --help

For more detail on using Gradle, see https://docs.gradle.org/7.5.1/userguide/command_line_interface.html

For troubleshooting, visit https://help.gradle.org

Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

See https://docs.gradle.org/7.5.1/userguide/command_line_interface.html#sec:command_line_warnings

BUILD SUCCESSFUL in 13s
6 actionable tasks: 1 executed, 5 up-to-date

Sunbreak avatar Nov 19 '22 07:11 Sunbreak

BTW, ln -s ~/.volta/bin/node /usr/local/bin/node and REBOOT don't help either

Sunbreak avatar Nov 19 '22 08:11 Sunbreak

Here's the project: mylib.zip

Sunbreak avatar Nov 19 '22 08:11 Sunbreak

Thank you for the super details repro steps @Sunbreak! I'm not on a Mac machine at the moment, but I'll definitely look to try those out as soon as I can, to see if I can understand what exactly is getting disconnected in this case.

charlespierce avatar Dec 03 '22 20:12 charlespierce

I am having the same issue, but via a Fastlane build. The solutions provided in the linked issue did not provide a solution for me.

Fastlane cli output:

bundler: failed to load command: fastlane (/Users/xxx/Development/xxx/app/vendor/bundle/ruby/2.7.0/bin/fastlane)
FastlaneCore::Interface::FastlaneShellError: [!] Exit status of command '/Users/xxx/Development/xxx/app/android/gradlew clean -p /Users/xxx/Development/xxx/app/android' was 1 instead of 0.
:ReactNative:Unexpected empty result of running '[node, -e, try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}]' command.
:ReactNative:Running '[node, -e, try {console.log(require('@react-native-community/cli').bin);} catch (e) {console.log(require('react-native/cli').bin);}]' command failed.

FAILURE: Build failed with an exception.

* Where:
Script '/Users/xxx/Development/xxx/app/node_modules/@react-native-community/cli-platform-android/native_modules.gradle' line: 413

* What went wrong:
A problem occurred evaluating script.
> Volta error: Node is not available.To run any Node command, first set a default version using `volta install node`Error details written to /Users/xxx/.volta/log/volta-error-2023-02-22_17_12_22.698.log

Volta error log:

"node" "-e" "try {console.log(require(\'@react-native-community/cli\').bin);} catch (e) {console.log(require(\'react-native/cli\').bin);}"
Volta v1.1.1

Node is not available.

To run any Node command, first set a default version using `volta install node`

Error cause: Resource temporarily unavailable (os error 35)

idlework avatar Feb 22 '23 16:02 idlework

Run Android build

  • STOP yarn example android
  • cd example/android
  • ./gradlew failed while ./gradlew --no-daemon work

Fastlane was actually calling ./gradlew command. Try add --no-daemon

Sunbreak avatar Feb 22 '23 23:02 Sunbreak

@Sunbreak Thank you very much for the quick reply. I tried your solution, and it works.

To reproduce it with cli use: ./android/gradlew bundleRelease --project-dir ./android To fix it with cli use the no daemon param: ./android/gradlew bundleRelease --project-dir ./android --no-daemon

With Fastlane pass the no daemon param via flags:

gradle(
    task: 'bundleRelease'
    project_dir: File.absolute_path('../android'),
    flags: "--no-daemon"
)

Thanks!

idlework avatar Feb 23 '23 11:02 idlework

Sporadically also getting this error.

Cant put my finger on it, but it seems to occur when I open VS-Code BEFORE opening the terminal app.

Rebooting my computer helped.

(Also ran volta setup and unset _VOLTA_TOOL_RECURSION in each before reboot)

lauhon avatar Jan 26 '24 13:01 lauhon

Running pkill -f '.*GradleDaemon.*' whenever I encounter it does the trick.

rickymohk avatar Mar 13 '24 04:03 rickymohk

Running pkill -f '.*GradleDaemon.*' whenever I encounter it does the trick.

./gradlew --stop is enough, especially for Windows

Sunbreak avatar Mar 15 '24 11:03 Sunbreak

Running pkill -f '.*GradleDaemon.*' whenever I encounter it does the trick.

This worked for me on my M3 Mac

Literally tried all the other suggestions on here. I also have this in my .zshrc, .bashrc, and .profile files.

export VOLTA_HOME=$HOME/.volta
export PATH=$VOLTA_HOME/bin:$PATH
unset _VOLTA_TOOL_RECURSION in each

jaaywags avatar May 15 '24 00:05 jaaywags