LavaMoat / docs

React Native docs
1 stars 3 forks source link

RN 0.66.5 + RN CLI: PhaseScriptExecution error (not with Xcode) #15

Closed leotm closed 1 year ago

leotm commented 1 year ago

Follow-up to


From npx react-native@0.66.5 init RN0665 --version 0.66.5

yarn start --reset-cache

yarn ios

nvm is not compatible with the "PREFIX" environment variable: currently set to "/usr/local"
Run `unset PREFIX` to unset it.
Command PhaseScriptExecution failed with a nonzero exit code

The build error is now happening consistently for fresh RN projects, with unset PREFIX to no avail

Likely related to nvm from metamask-mobile setup (no other node manager in use) nb: also running react-native+0.66.5.patch

If unable to figure soon, stick to Xcode (14.2 stable) for now i.e. not a blocker

nvm --version # 0.39.3
which nvm # nvm function definition: https://pastebin.com/CwvhKUN0
node --version # v14.21.3
which node # /opt/homebrew/opt/node@14/bin/node

echo $PATH

/opt/homebrew/opt/node@14/bin:/Users/leo/.rbenv/shims:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/Users/leo/Library/Android/sdk/emulator:/Users/leo/Library/Android/sdk/tools:/Users/leo/Library/Android/sdk/tools/bin:/Users/leo/Library/Android/sdk/platform-tools

leotm commented 1 year ago

This is likely fine with Xcode since

https://github.com/facebook/react-native/blob/0.66-stable/scripts/react-native-xcode.sh#L84 is calling

# Find path to Node
# shellcheck source=/dev/null
source "$REACT_NATIVE_DIR/scripts/find-node.sh"

# check and assign NODE_BINARY env
# shellcheck source=/dev/null
source "$REACT_NATIVE_DIR/scripts/node-binary.sh"

# ...

"$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \
  $CONFIG_ARG \
  --entry-file "$ENTRY_FILE" \
  --platform "$BUNDLE_PLATFORM" \
  --dev $DEV \
  --reset-cache \
  --bundle-output "$BUNDLE_FILE" \
  --assets-dest "$DEST" \
  $EXTRA_ARGS \
  $EXTRA_PACKAGER_ARGS

# ...

Different to our RN CLI

https://github.com/facebook/react-native/blob/0.66-stable/scripts/find-node.sh

#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

set -e

# Support Homebrew on M1
HOMEBREW_M1_BIN=/opt/homebrew/bin
if [[ -d $HOMEBREW_M1_BIN && ! $PATH =~ $HOMEBREW_M1_BIN ]]; then
  export PATH="$HOMEBREW_M1_BIN:$PATH"
fi

# Define NVM_DIR and source the nvm.sh setup script
[ -z "$NVM_DIR" ] && export NVM_DIR="$HOME/.nvm"

if [[ -s "$HOME/.nvm/nvm.sh" ]]; then
  # shellcheck source=/dev/null
  . "$HOME/.nvm/nvm.sh"
elif [[ -x "$(command -v brew)" && -s "$(brew --prefix nvm)/nvm.sh" ]]; then
  # shellcheck source=/dev/null
  . "$(brew --prefix nvm)/nvm.sh"
fi

# Set up the nodenv node version manager if present
if [[ -x "$HOME/.nodenv/bin/nodenv" ]]; then
  eval "$("$HOME/.nodenv/bin/nodenv" init -)"
elif [[ -x "$(command -v brew)" && -x "$(brew --prefix nodenv)/bin/nodenv" ]]; then
  eval "$("$(brew --prefix nodenv)/bin/nodenv" init -)"
fi

# Set up the ndenv of anyenv if preset
if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
  export PATH=${HOME}/.anyenv/bin:${PATH}
  if [[ "$(anyenv envs | grep -c ndenv )" -eq 1 ]]; then
    eval "$(anyenv init -)"
  fi
fi

https://github.com/facebook/react-native/blob/0.66-stable/scripts/node-binary.sh

#!/bin/bash
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"

nodejs_not_found()
{
  echo "error: Can't find the '$NODE_BINARY' binary to build the React Native bundle. " \
       "If you have a non-standard Node.js installation, select your project in Xcode, find " \
       "'Build Phases' - 'Bundle React Native code and images' and change NODE_BINARY to an " \
       "absolute path to your node executable. You can find it by invoking 'which node' in the terminal." >&2
  exit 2
}

type "$NODE_BINARY" >/dev/null 2>&1 || nodejs_not_found
leotm commented 1 year ago

nvm unalias default 🎉 until find a better solution compatible with nvm and other node version managers

Screenshot 2023-03-06 at 19 28 16
leotm commented 1 year ago