Skip to content

Commit

Permalink
find-node.sh supports Homebrew on M1 (facebook#31622)
Browse files Browse the repository at this point in the history
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 facebook#31621 facebook#31592

## Changelog

[General] [Changed] - find-node.sh supports Homebrew on M1

Pull Request resolved: facebook#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
  • Loading branch information
dulmandakh authored and Setito committed Jul 17, 2021
1 parent 7097299 commit 50e505d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 3 additions & 9 deletions react.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ def detectCliPath(config) {
if (config.cliPath) {
return config.cliPath
}

def cliPath = ["node", "-e", "console.log(require('react-native/cli').bin);"].execute([], projectDir).text.trim()

if (cliPath) {
return cliPath
} else if (new File("${projectDir}/../../node_modules/react-native/cli.js").exists()) {
if (new File("${projectDir}/../../node_modules/react-native/cli.js").exists()) {
return "${projectDir}/../../node_modules/react-native/cli.js"
} else {
throw new Exception("Couldn't determine CLI location. " +
"Please set `project.ext.react.cliPath` to the path of the react-native cli.js");
}
throw new Exception("Couldn't determine CLI location. " +
"Please set `project.ext.react.cliPath` to the path of the react-native cli.js");
}

def composeSourceMapsPath = config.composeSourceMapsPath ?: "node_modules/react-native/scripts/compose-source-maps.js"
Expand Down
6 changes: 6 additions & 0 deletions scripts/find-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ if [[ ! -x node && -d ${HOME}/.anyenv/bin ]]; then
eval "$(anyenv init -)"
fi
fi

# 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

0 comments on commit 50e505d

Please sign in to comment.