Skip to content

Commit 502b819

Browse files
dulmandakhfacebook-github-bot
authored andcommitted
find-node.sh supports Homebrew on M1 (#31622)
Summary: Homebrew on M1 installs executable binaries in **/opt/homebrew/bin** (See https://brew.sh/2021/02/05/homebrew-3.0.0/), and FBReactNativeSpec.build is failing because it couldn't find node. This PR changes find-node.sh script to add /opt/homebrew/bin into $PATH. The way **react.gradle** trying to execute node is not using user environment variables, but system defaults, so it couldn't find it. I removed node execution, and hard coded cli path in parity with iOS https://github.com/facebook/react-native/blob/d1ab03235cb4b93304150878d2b9057ab45bba77/scripts/react-native-xcode.sh#L106 Fixes #31621 #31592 ## Changelog [General] [Changed] - find-node.sh supports Homebrew on M1 Pull Request resolved: #31622 Test Plan: On M1, create a RN project and it'll fail to build iOS app. Apply the patch, and build will succeed. Reviewed By: ShikaSD Differential Revision: D28808206 Pulled By: hramos fbshipit-source-id: 8b313b6685462a15e67d99c61a0202d17fece1ec
1 parent 1538fa4 commit 502b819

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

react.gradle

+3-9
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,11 @@ def detectCliPath(config) {
2828
if (config.cliPath) {
2929
return config.cliPath
3030
}
31-
32-
def cliPath = ["node", "-e", "console.log(require('react-native/cli').bin);"].execute([], projectDir).text.trim()
33-
34-
if (cliPath) {
35-
return cliPath
36-
} else if (new File("${projectDir}/../../node_modules/react-native/cli.js").exists()) {
31+
if (new File("${projectDir}/../../node_modules/react-native/cli.js").exists()) {
3732
return "${projectDir}/../../node_modules/react-native/cli.js"
38-
} else {
39-
throw new Exception("Couldn't determine CLI location. " +
40-
"Please set `project.ext.react.cliPath` to the path of the react-native cli.js");
4133
}
34+
throw new Exception("Couldn't determine CLI location. " +
35+
"Please set `project.ext.react.cliPath` to the path of the react-native cli.js");
4236
}
4337

4438
def composeSourceMapsPath = config.composeSourceMapsPath ?: "node_modules/react-native/scripts/compose-source-maps.js"

scripts/find-node.sh

+6
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,9 @@ if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
3131
eval "$(anyenv init -)"
3232
fi
3333
fi
34+
35+
# Support Homebrew on M1
36+
HOMEBREW_M1_BIN=/opt/homebrew/bin
37+
if [[ -d $HOMEBREW_M1_BIN && ! $PATH =~ $HOMEBREW_M1_BIN ]]; then
38+
export PATH="$HOMEBREW_M1_BIN:$PATH"
39+
fi

0 commit comments

Comments
 (0)