volta-cli / volta

Volta: JS Toolchains as Code. ⚡
https://volta.sh
Other
11.17k stars 238 forks source link

Node is not available in React Native #1352

Open c0d3x opened 2 years ago

c0d3x commented 2 years ago

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?

charlespierce commented 2 years ago

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?

Sunbreak commented 2 years ago

Encountered on an initially setup macOS 12.6.1

Environment

env
```sh $ 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
```sh $ 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
```sh $ 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
```sh $ cat ~/.bash_profile ######################### # Profile for /bin/bash # ######################### # Volta & Node export VOLTA_HOME="$HOME/.volta" export PATH="$VOLTA_HOME/bin:$PATH" ```
cat ~/.profile
```sh $ cat ~/.profile ####################### # Profile for /bin/sh # ####################### # Volta & Node export VOLTA_HOME="$HOME/.volta" export PATH="$VOLTA_HOME/bin:$PATH" ```
brew list
```sh $ brew list ==> Formulae cocoapods pcre the_silver_searcher xz ```
java -version
```sh $ 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
```sh $ xcodebuild -version Xcode 14.0 Build version 14A309 ```

Reproduce

Setup mylib

```sh $ 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? … sunbreak.wang@gmail.com ✔ 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 ```
```sh $ 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 > source-map-resolve@0.5.3: 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 > uglify-es@3.3.9: 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 > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated [2/4] 🚚 Fetching packages... [3/4] 🔗 Linking dependencies... warning "react-native > react-native-codegen > jscodeshift@0.13.1" 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/lefthook@0.7.7: @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 > source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > urix@0.1.0: Please see https://github.com/lydell/urix#deprecated warning react-native > react-native-codegen > jscodeshift > micromatch > snapdragon > source-map-resolve > resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated warning react-native > @react-native-community/cli > @react-native-community/cli-plugin-metro > metro > metro-minify-uglify > uglify-es@3.3.9: support for ECMAScript is superseded by `uglify-js` as of v3.13.0 [2/4] 🚚 Fetching packages... [3/4] 🔗 Linking dependencies... warning "react-native > metro-react-native-babel-transformer@0.72.3" has unmet peer dependency "@babel/core@*". warning "react-native > react-native-codegen > jscodeshift@0.13.1" 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 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

$ ./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 commented 2 years ago

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

Sunbreak commented 2 years ago

Here's the project: mylib.zip

charlespierce commented 1 year ago

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.

idlework commented 1 year ago

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)
Sunbreak commented 1 year ago

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

idlework commented 1 year ago

@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!

lauhon commented 10 months ago

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)

rickymohk commented 8 months ago

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

Sunbreak commented 8 months ago

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

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

jaaywags commented 6 months ago

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