Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MacOS: realpath not found #34146

Closed
squio opened this issue Jul 6, 2022 · 26 comments
Closed

MacOS: realpath not found #34146

squio opened this issue Jul 6, 2022 · 26 comments
Labels
Resolution: Answered When the issue is resolved with a simple answer

Comments

@squio
Copy link

squio commented Jul 6, 2022

Description

The realpath command does not exist on MacOs.

Commit bb8ddd6 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"

@alexanderoskin
Copy link

Same

@zkylearner
Copy link

same

@jamesqo
Copy link

jamesqo commented Jul 12, 2022

I'm having the same issue

@Alt-er
Copy link

Alt-er commented Jul 13, 2022

same 😭

@DevJett
Copy link

DevJett commented Jul 13, 2022

I fixed the issue you need to install coreutils

brew install coreutils

Make sure to clearn build folder (Product -> Clean Build Folder)

@squio
Copy link
Author

squio commented Jul 13, 2022

I fixed the issue you need to install coreutils

brew install coreutils

Make sure to clearn build folder (Product -> Clean Build Folder)

Sorry but that is patching the problem by installing a backward compatibility shim for pre-2000 state

While this commit bb8ddd6 explicitly removes the current cross-platform command. Just why?

@biallo
Copy link

biallo commented Aug 1, 2022

Same, version 0.69.3

@cortinico
Copy link
Contributor

While this commit bb8ddd6 explicitly removes the current cross-platform command. Just why?

To provide context here: readlink didn't work with the new build setup we have internally. Every occurrence of readlink was replaced with realpath with a search-n-replace inside bb8ddd6

If you list the usages that needs to be reverted back, we can address them 👍

@Jarvie789
Copy link

same 😭😭

@BS-FastwebIT
Copy link

BS-FastwebIT commented Sep 28, 2022

same, version 0.70.1
but i can continue to work... metro run and application too :| but isnt a warning..

@zheoreh
Copy link

zheoreh commented Sep 28, 2022

Same on MacOS 12.6, node v12.16.3, react-native 0.70.1

`Node found at: /usr/local/bin/node
/Users/mac/Documents/Projects/puertomap/node_modules/react-native/scripts/packager.sh: line 8: realpath: command not found
/Users/mac/Documents/Projects/puertomap/node_modules/@react-native-community/cli/build/index.js:156
cmd.option(opt.name, opt.description ?? '', opt.parse || (val => val), typeof opt.default === 'function' ? opt.default(rest[0]) : opt.default);
^

SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:1047:16)
at Module._compile (internal/modules/cjs/loader.js:1097:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
at Module.load (internal/modules/cjs/loader.js:977:32)
at Function.Module._load (internal/modules/cjs/loader.js:877:14)
at Module.require (internal/modules/cjs/loader.js:1019:19)
at require (internal/modules/cjs/helpers.js:77:18)
at Object. (/Users/mac/Documents/Projects/puertomap/node_modules/react-native/cli.js:13:11)
at Module._compile (internal/modules/cjs/loader.js:1133:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
Process terminated. Press to close the window`

@cortinico
Copy link
Contributor

Same on MacOS 12.6, node v12.16.3, react-native 0.70.1

Quick heads up that node 12 is not supported by React Native. Min version is 14.
Also @zheoreh, are you invoking ./scripts/packager.sh directly or using another command?

@zheoreh
Copy link

zheoreh commented Oct 4, 2022

@cortinico I just run react-native run-android && (npm run adb || true) && npm run log-android and it automatically open a new terminal and starts metro. In some way I was able to get node version within that terminal and it was node 12 but I use nvm and default version of node is v16.15.0. I don't know why it uses /usr/local/bin/node instead of /Users/mac/.nvm/versions/node/v16.15.0/bin/node.

% node -v
v16.15.0
% which node            
/Users/mac/.nvm/versions/node/v16.15.0/bin/node

If I start metro myself then everything is ok.

@cortinico
Copy link
Contributor

I'm more concerned that you see ./scripts/packager.sh in your stacktrace:

/Users/mac/Documents/Projects/puertomap/node_modules/react-native/scripts/packager.sh: line 8: realpath: command not found

Which is a script that is internal to React Native and you should not be calling. I'm wondering why it's there.

@Mr-Rith
Copy link

Mr-Rith commented Oct 17, 2022

same😭😭

@cortinico
Copy link
Contributor

Can someone please clarify if:

  1. You're experiencing this in your own project or by cloning react-native?
  2. brew install coreutils solves your issue or not?

@deftcat
Copy link

deftcat commented Oct 19, 2022

brew install coreutils solves my issue. 🎉

@cortinico
Copy link
Contributor

brew install coreutils solves my issue. 🎉

I'm going to close this issue as brew install coreutils seems to be the valid answer.

I still have a couple of open questions:

  1. Are you folks experiencing this in your own project or by cloning react-native?
  2. Is this happening in a vanilla project or not?

We might need to either:

  1. Update the docs to suggest brew install coreutils to everyone
  2. Update the offending script to remove realpath.

I would need further context to understand what's the follow up here.

@cortinico cortinico added the Resolution: Answered When the issue is resolved with a simple answer label Oct 19, 2022
@anaclette
Copy link

anaclette commented Oct 19, 2022

brew install coreutils worked for me too, but right after having cleaned and rebuilt my project from xcode xcworkspace. To answer @cortinico's question, in my case I was experiencing this issue in a react native project of my own.

@shrekuu
Copy link

shrekuu commented Oct 20, 2022

@cortinico It seems it is fixed in this commit: #34145
Apple removes stuff and break things. We need to use the latest version of React Native or brew install coreutils.

@AsteriskZuo
Copy link

AsteriskZuo commented Nov 6, 2022

brew install coreutils solves my issue. 🎉

I'm going to close this issue as brew install coreutils seems to be the valid answer.

I still have a couple of open questions:

1. Are you folks experiencing this in your own project or by cloning react-native?

2. Is this happening in a vanilla project or not?

We might need to either:

1. Update the docs to suggest `brew install coreutils` to everyone

2. Update the offending script to remove `realpath`.

I would need further context to understand what's the follow up here.

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'.

@AsteriskZuo
Copy link

AsteriskZuo commented Nov 6, 2022

I suggest using the command realpath -> readlink -f instead. It's much more reliable than installing a bunch of commands.

THIS_DIR=$(cd -P "$(dirname "$(readlink -f "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd)

@ariccio
Copy link

ariccio commented Nov 24, 2022

Just bumped into this in an expo bare project. Hmph.

@cortinico
Copy link
Contributor

Just to re-iterate, this is fixed in 0.71 (at least for the packager.sh script).

@adarleyjrr
Copy link

@cortinico I just run react-native run-android && (npm run adb || true) && npm run log-android and it automatically open a new terminal and starts metro. In some way I was able to get node version within that terminal and it was node 12 but I use nvm and default version of node is v16.15.0. I don't know why it uses /usr/local/bin/node instead of /Users/mac/.nvm/versions/node/v16.15.0/bin/node.

% node -v
v16.15.0
% which node            
/Users/mac/.nvm/versions/node/v16.15.0/bin/node

If I start metro myself then everything is ok.

For anyone struggling with this, I found out that the realpath: command not found might not be the root cause of your Metro not being able to start. The reason it's not starting is probably because you have multiple installations of npm/yarn, as mentioned in this issue. Following the steps from that same comment to uninstall and reinstall them resolved my problem. (I still see the realpath: command not found when running react-native run-ios, but Metro startup no longer breaks, and works normally)

@winmuse
Copy link

winmuse commented Mar 5, 2023

same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: Answered When the issue is resolved with a simple answer
Projects
None yet
Development

No branches or pull requests