react-native: MacOS: realpath not found
Description
The realpath
command does not exist on MacOs.
Commit bb8ddd6c1247fde230a60c662a318422df52516e uses realpath
instead of readlink
.
Changing this in ./scripts/packager.sh
resolved this issue for me (MacOs Montery, Silicon M1):
THIS_DIR=$(cd -P "$(dirname "$(readlink -f "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)
where realpath
is replaced by readlink -f
NOTE: readlink
appears to be the more modern and more widely supported replacement for realpath
Version
0.69.1
Output of npx react-native info
System: OS: macOS 12.4 CPU: (8) arm64 Apple M1 Memory: 104.45 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node Yarn: 1.22.18 - ~/Library/pnpm/yarn npm: 8.13.2 - ~/Development/app/node_modules/.bin/npm Watchman: 2022.06.13.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5 Android SDK: API Levels: 28, 29, 31, 32, 33 Build Tools: 28.0.3, 29.0.2, 30.0.3, 31.0.0, 32.0.0, 33.0.0 System Images: android-29 | ARM 64 v8a, android-29 | Google APIs ARM 64 v8a, android-29 | Google Play ARM 64 v8a, android-31 | ARM 64 v8a, android-31 | Google APIs ARM 64 v8a, android-31 | Google Play ARM 64 v8a, android-32 | Google APIs ARM 64 v8a, android-32 | Google Play ARM 64 v8a, android-33 | Google APIs ARM 64 v8a, android-33 | Google Play ARM 64 v8a Android NDK: 22.1.7171670 IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8609683 Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild Languages: Java: 11.0.15 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: ^18.2.0 => 18.2.0 react-native: ^0.69.0 => 0.69.1 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Steps to reproduce
Run the Android debug build command on Mac Os:
npm run android
Watch the debugger terminal, the top line shows an error realpath not found
Snack, code example, screenshot, or link to a repository
Users/***/node_modules/react-native/scripts/packager.sh: line 8: realpath: command not found
#######
################
######### #########
######### ##########
######### ###### #########
##########################################
##### ##################### #####
##### ############## #####
##### ### ###### ### #####
##### ####### ####### #####
##### ########### ########### #####
##### ########################## #####
##### ########################## #####
##### ###################### ######
###### ############# #######
######### #### #########
######### #########
######### #########
#########
Welcome to Metro!
Fast - Scalable - Integrated
To reload the app press “r” To open developer menu press “d”
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 13
- Comments: 26 (6 by maintainers)
I fixed the issue you need to install
coreutils
Make sure to clearn build folder (Product -> Clean Build Folder)
This is not a good solution. This tool set has other tools, and it has the same name as the mac system’s built-in tools, which can cause more problems if you set environment variables. Fix the problem the right way, not with this flaky patch. ‘brew install coreutils’ After installation, environment variables need to be set
PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH
Many commands have the same name. For example, ‘ln’ ‘mv’.@cortinico It seems it is fixed in this commit: https://github.com/facebook/react-native/pull/34145 Apple removes stuff and break things. We need to use the latest version of React Native or
brew install coreutils
.Just to re-iterate, this is fixed in 0.71 (at least for the packager.sh script).
brew install coreutils
solves my issue. 🎉