Skip to content

Commit

Permalink
Fix: use NODE_BINARY when starting packager (#24156)
Browse files Browse the repository at this point in the history
Summary:
Fix packager script to use `NODE_BINARY` env variable.

Should fix #22868

[iOS] [Fixed] - Use `NODE_BINARY` env variable in `packager.sh` script
Pull Request resolved: #24156

Differential Revision: D14870783

Pulled By: cpojer

fbshipit-source-id: 27ecf8bf59883920ab51478b8a4d8f0780e34664
  • Loading branch information
Esemesek authored and facebook-github-bot committed Apr 10, 2019
1 parent a05b409 commit 265ae58
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"scripts/launchPackager.command",
"scripts/packager.sh",
"scripts/react-native-xcode.sh",
"scripts/node-binary.sh",
"jest-preset.js",
"jest",
"lib",
Expand Down
18 changes: 18 additions & 0 deletions scripts/node-binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/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
6 changes: 5 additions & 1 deletion scripts/packager.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ PROJECT_ROOT="$THIS_DIR/../../.."
# shellcheck source=/dev/null
source "${THIS_DIR}/.packager.env"

# check and assign NODE_BINARY env
# shellcheck disable=SC1091
source "${THIS_DIR}/node-binary.sh"

# When running react-native tests, react-native doesn't live in node_modules but in the PROJECT_ROOT
if [ ! -d "$PROJECT_ROOT/node_modules/react-native" ];
then
PROJECT_ROOT="$THIS_DIR/.."
fi
# Start packager from PROJECT_ROOT
cd "$PROJECT_ROOT" || exit
node "$REACT_NATIVE_ROOT/cli.js" start "$@"
"$NODE_BINARY" "$REACT_NATIVE_ROOT/cli.js" start "$@"
16 changes: 3 additions & 13 deletions scripts/react-native-xcode.sh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
fi
fi

[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"
# check and assign NODE_BINARY env
# shellcheck disable=SC1091
source './node-binary.sh'

[ -z "$NODE_ARGS" ] && export NODE_ARGS=""

Expand All @@ -107,18 +109,6 @@ else
CONFIG_ARG="--config $BUNDLE_CONFIG"
fi

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

type "$NODE_BINARY" >/dev/null 2>&1 || nodejs_not_found

BUNDLE_FILE="$DEST/main.jsbundle"

"$NODE_BINARY" $NODE_ARGS "$CLI_PATH" $BUNDLE_COMMAND \
Expand Down

3 comments on commit 265ae58

@hramos
Copy link
Contributor

@hramos hramos commented on 265ae58 Apr 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Esemesek this seems to have broken the iOS end-to-end tests. You can repro by running:

yarn build-ios-e2e

The error is: node-binary.sh: No such file or directory

@Esemesek
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me investigate. Probably paths to the script are incorrect.

@hramos
Copy link
Contributor

@hramos hramos commented on 265ae58 Apr 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I briefly looked into this, and fixing the path to node-binary.sh unearths another failure further down:

error Unable to find React Native files. Make sure "react-native" module is installed in your project dependencies. If you are using React Native from a non-standard location, consider setting: { "react-native": { "reactNativePath": "./path/to/react-native" } } in your `package.json`. Run CLI with --verbose flag for more details.
+ [[ false != true ]]
+ [[ ! -f /Users/hramos/git/react-native/RNTester/build/Build/Products/Release-iphonesimulator/RNTester.app/main.jsbundle ]]
+ echo 'error: File /Users/hramos/git/react-native/RNTester/build/Build/Products/Release-iphonesimulator/RNTester.app/main.jsbundle does not exist. This must be a bug with'
error: File /Users/hramos/git/react-native/RNTester/build/Build/Products/Release-iphonesimulator/RNTester.app/main.jsbundle does not exist. This must be a bug with
+ echo 'React Native, please report it here: https://github.com/facebook/react-native/issues'
React Native, please report it here: https://github.com/facebook/react-native/issues

The node-binary.sh fix I used was the following (in react-native-xcode.sh):

# shellcheck disable=SC1091
source "$REACT_NATIVE_DIR/scripts/node-binary.sh"

Please sign in to comment.