React-native: /bin/bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory

Created on 3 Mar 2020  路  17Comments  路  Source: facebook/react-native

Description:

As suggested by the docs, I uninstalled global react-native-cli, and use npx instead.
I encounter this error when running :
npx react-native init AwesomeProject
as the error suggests, I run
cd ./AwesomeProject/ios && pod install
But still get the same error during installation of glog as follow:

/bin/bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory

React Native version:

Run `react-native info` in your terminal and copy the results here.

bash: react-native: command not found

Steps To Reproduce

  1. brew install node
  2. brew install watchman
  3. sudo gem install cocoapods -n /usr/local/bin
  4. npx react-native init AwesomeProject

Expected Results

An error during Installing glog (0.3.5).

Installing glog (0.3.5)
[!] /bin/bash -c
set -e

!/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.

set -e

PLATFORM_NAME="${PLATFORM_NAME:-iphoneos}"
CURRENT_ARCH="${CURRENT_ARCH}"

if [ -z "$CURRENT_ARCH" ] || [ "$CURRENT_ARCH" == "undefined_arch" ]; then
# Xcode 10 beta sets CURRENT_ARCH to "undefined_arch", this leads to incorrect linker arg.
# it's better to rely on platform name as fallback because architecture differs between simulator and device

if [[ "$PLATFORM_NAME" == *"simulator"* ]]; then
    CURRENT_ARCH="x86_64"
else
    CURRENT_ARCH="armv7"
fi

fi

export CC="$(xcrun -find -sdk $PLATFORM_NAME cc) -arch $CURRENT_ARCH -isysroot $(xcrun -sdk $PLATFORM_NAME --show-sdk-path)"
export CXX="$CC"

Remove automake symlink if it exists

if [ -h "test-driver" ]; then
rm test-driver
fi

./configure --host arm-apple-darwin

Fix build for tvOS

cat << EOF >> src/config.h

/* Add in so we have Apple Target Conditionals */

ifdef __APPLE__

include

include

endif

/* Special configuration for AppleTVOS */

if TARGET_OS_TV

undef HAVE_SYSCALL_H

undef HAVE_SYS_SYSCALL_H

undef OS_MACOSX

endif

/* Special configuration for ucontext */

undef HAVE_UCONTEXT_H

undef PC_FROM_UCONTEXT

if defined(__x86_64__)

define PC_FROM_UCONTEXT uc_mcontext->__ss.__rip

elif defined(__i386__)

define PC_FROM_UCONTEXT uc_mcontext->__ss.__eip

endif

EOF

Prepare exported header include

EXPORTED_INCLUDE_DIR="exported/glog"
mkdir -p exported/glog
cp -f src/glog/log_severity.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/logging.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/raw_logging.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/stl_logging.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/vlog_is_on.h "$EXPORTED_INCLUDE_DIR/"

/bin/bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory

Needs

Most helpful comment

hat tip to elpardo farther down in this thread

  • check your git's global autocrlf setting

    • git config --global core.autocrlf

    • repository one doesn't matter for this issue (my repo setting was right but my global one was wrong)

  • if it isn't already, set it to input on macOS (false also works, see documentation link below)

    • git config --global --add core.autocrlf input

git's core.autocrlf documentation


Hacky workaround spoilered to avoid misleading
used these instructions a couple of days ago after reading a few dozen comments across several threads
for convenience, most lines can be triple clicked to copy/paste
assumed you are comfortable editing in vi, if not, you'll need to adjust as necessary

on ios

  • starting from RN project root
  • vi node_modules/react-native/scripts/ios-configure-glog.sh

    • :w ++ff=mac

    • saves in mac line endings

  • vi node_modules/react-native/scripts/ios-install-third-party.sh

    • replace SCRIPTDIR=$(dirname "$0") with

    • SCRIPTDIR=$(pwd)/$(dirname "$0")

    • replace fetch_and_unpack glog-0.3.5.tar.gz https://github.com/google/glog/archive/v0.3.5.tar.gz 61067502c5f9769d111ea1ee3f74e6ddf0a5f9cc "\"$SCRIPTDIR/ios-configure-glog.sh\"" with

    • fetch_and_unpack glog-0.3.5.tar.gz https://github.com/google/glog/archive/v0.3.5.tar.gz 61067502c5f9769d111ea1ee3f74e6ddf0a5f9cc "sh \"$SCRIPTDIR/ios-configure-glog.sh\""

    • :wq

  • cd node_modules/react-native/scripts/ && ./ios-install-third-party.sh
  • cd third-party/ && cd glog-0.3.5/src && ./configure && ./make && cd ../..
  • cp -a glog-0.3.5/src/. ../../../../ios/Pods/glog/src/ && cp -a folly-2018.10.22.00/folly/. ../../../../ios/Pods/Folly/folly
  • cd ../../../../ios && pod update

All 17 comments

Same issue, I have been trying to fix this since yesterday with various ways to convert the character, used dos2unix, vim fileformat=unix and a lot, nothing works. Am using MacOS with pod install (already remove entire Pods directory), so no possibility of getting the file accidentally opened or edited on windows.

@ASaputra2019 open the file node_modules/react-native/scripts/ios-configure-glog.sh in Sublime Text editor, change the line endings with View > Line Endings > Mac OS 9, save and try pod install, it works. Note: It doesn't works when you change to Unix line endings so must to Mac OS 9 in sublime text or some equivalent mac line ending from other tools.

@JohnpeterDairianadan Thank you so much, it solved my problem that has been on my mind since yesterday too. Similar to you, I tried with dos2unix, also with vi and vim, but to no avail.. Crashed my environment trying to change anything in the process... But finally with Sublime Text it works! Thank you!!

good to hear, but I would prefer to keep the issue open, as we remove node_modules sometime and wont exist in switching environment, so it is still an open issue, I just tried a workaround.

actually View > Line Endings > Mac OS 9, save and try pod install, it works. but after that run react-native run-ios command return

config.h dosn't found in mutex.h. this issue opened on 2018
https://github.com/facebook/react-native/issues/19774

I don't understand, now no one ios dev. dosn't use react-native on ios
My setup new, maybe it was my fauld

System:
OS: macOS 10.15.3
CPU: (4) x64 Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
Memory: 207.86 MB / 8.00 GB
Shell: 5.7.1 - /bin/zsh
Binaries:
Node: 13.8.0 - /usr/local/bin/node
Yarn: 1.22.0 - /usr/local/bin/yarn
npm: 6.13.7 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
IDEs:
Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
npmPackages:
react: 16.9.0 => 16.9.0
react-native: 0.61.5 => 0.61.5
npmGlobalPackages:
react-native-cli: 2.0.1

@OkancanCosar I got this issue solved yesterday with manually installed the third party libs glog, folly etc with the scripts under react-native node_module dir, and building the glog with cmake configure and make, then copied that to pod's glog dir, then it works. https://github.com/facebook/react-native/issues/22703#issuecomment-450486198.. But instead of the change in script made in the linked comment, I did

# SCRIPTDIR=$(dirname "$0")
SCRIPTDIR=$(pwd)/$(dirname "$0")
fetch_and_unpack glog-0.3.5.tar.gz https://github.com/google/glog/archive/v0.3.5.tar.gz 61067502c5f9769d111ea1ee3f74e6ddf0a5f9cc "sh \"$SCRIPTDIR/ios-configure-glog.sh\""

sorry for my dummy :(
react-native init myproj
err => /bin/bash: ./configure: /bin/sh^M: bad interpreter: No such file or directory
node_modules/react-native/scripts/ios-configure-glog.sh => View > Line Endings > Mac OS 9, save and run pod install

i expect there is folder named node_modules/react-native/third_party but not.
react-native run-ios
err => myproj/ios/Pods/glog/src/base/mutex.h:105:10: fatal error: 'config.h' file not found

then

node_modules/react-native/scripts/ios-install-third-party.sh change

SCRIPTDIR=$(pwd)/$(dirname "$0")
fetch_and_unpack glog-0.3.5.tar.gz https://github.com/google/glog/archive/v0.3.5.tar.gz 61067502c5f9769d111ea1ee3f74e6ddf0a5f9cc "sh "$SCRIPTDIR/ios-configure-glog.sh""

cd node_modules/react-native/ && scripts/ios-install-third-party.sh

and now created node_modules/react-native/third_party folder.
and then run-ios

still myproj/ios/Pods/glog/src/base/mutex.h:105:10: fatal error: 'config.h' file not found

after the third_party folder gets created and the glog, folly etc are fetched, go inside the glog directory (or may be to sub dir in the glog where configure file exist), then ./configure, then ./make, those missing config.h and other files will get created now, then copy all the files created under src, replace with pods glog dir then similary do for folly, but for folly you dont need to ./configure or ./make. just replace the files in pod folly. then run-ios it should build

I got the same problem, but I found #22703(comment) solved my issue instead of going to run the ios-configure-glog.sh or copy folders around. Hope this helpful.

hat tip to elpardo farther down in this thread

  • check your git's global autocrlf setting

    • git config --global core.autocrlf

    • repository one doesn't matter for this issue (my repo setting was right but my global one was wrong)

  • if it isn't already, set it to input on macOS (false also works, see documentation link below)

    • git config --global --add core.autocrlf input

git's core.autocrlf documentation


Hacky workaround spoilered to avoid misleading
used these instructions a couple of days ago after reading a few dozen comments across several threads
for convenience, most lines can be triple clicked to copy/paste
assumed you are comfortable editing in vi, if not, you'll need to adjust as necessary

on ios

  • starting from RN project root
  • vi node_modules/react-native/scripts/ios-configure-glog.sh

    • :w ++ff=mac

    • saves in mac line endings

  • vi node_modules/react-native/scripts/ios-install-third-party.sh

    • replace SCRIPTDIR=$(dirname "$0") with

    • SCRIPTDIR=$(pwd)/$(dirname "$0")

    • replace fetch_and_unpack glog-0.3.5.tar.gz https://github.com/google/glog/archive/v0.3.5.tar.gz 61067502c5f9769d111ea1ee3f74e6ddf0a5f9cc "\"$SCRIPTDIR/ios-configure-glog.sh\"" with

    • fetch_and_unpack glog-0.3.5.tar.gz https://github.com/google/glog/archive/v0.3.5.tar.gz 61067502c5f9769d111ea1ee3f74e6ddf0a5f9cc "sh \"$SCRIPTDIR/ios-configure-glog.sh\""

    • :wq

  • cd node_modules/react-native/scripts/ && ./ios-install-third-party.sh
  • cd third-party/ && cd glog-0.3.5/src && ./configure && ./make && cd ../..
  • cp -a glog-0.3.5/src/. ../../../../ios/Pods/glog/src/ && cp -a folly-2018.10.22.00/folly/. ../../../../ios/Pods/Folly/folly
  • cd ../../../../ios && pod update

used these instructions a couple of days ago after reading a few dozen comments across several threads
for convenience, most lines can be triple clicked to copy/paste
assumed you are comfortable editing in vi, if not, you'll need to adjust as necessary

on ios

  • starting from RN project root
  • vi node_modules/react-native/scripts/ios-configure-glog.sh

    • :w ++ff=mac

    • saves in mac line endings

  • vi node_modules/react-native/scripts/ios-install-third-party.sh

    • replace SCRIPTDIR=$(dirname "$0") with

    • SCRIPTDIR=$(pwd)/$(dirname "$0")

    • replace fetch_and_unpack glog-0.3.5.tar.gz https://github.com/google/glog/archive/v0.3.5.tar.gz 61067502c5f9769d111ea1ee3f74e6ddf0a5f9cc "\"$SCRIPTDIR/ios-configure-glog.sh\"" with

    • fetch_and_unpack glog-0.3.5.tar.gz https://github.com/google/glog/archive/v0.3.5.tar.gz 61067502c5f9769d111ea1ee3f74e6ddf0a5f9cc "sh \"$SCRIPTDIR/ios-configure-glog.sh\""

    • :wq
  • cd node_modules/react-native/scripts/ && ./ios-install-third-party.sh
  • cd third-party/ && cd glog-0.3.5/src && ./configure && ./make && cd ../..
  • cp -a glog-0.3.5/src/. ../../../../ios/Pods/glog/src/ && cp -a folly-2018.10.22.00/folly/. ../../../../ios/Pods/Folly/folly
  • cd ../../../../ios && pod update

Thankyou, @EmperorEarth & everyone for your help!
I figured out what you meant after list files with ls command.
So just to make it clear for other people looking for this solution, on the 5th step, I ran ./configure from glog-0.3.5 directory. But run make from glog-0.3.5/src directory.

I ran into "permission denied" problem with copying all files from glog-0.3.5/src to AwesomeProject/ios/Pods/glog/src and also from folly-2018.10.22.00/folly to AwesomeProject/ios/Pods/Folly/folly - but this is because of my comp permission setup. So I did it manually with finder.

One more thing, after the first step: changing line-ending of ios-configure-glog.sh file - either with Sublime or with :w ++ff=mac - don't forget to run **pod install** from /AwesomeProject/ios, otherwise AwesomeProject/ios/Pods/glog will be empty, and we can't proceed with copying files on step 6.

I started experiencing the above issue a few weeks ago, wanted to post on here as I narrowed it down to a git config change I made on OSX.
Prior to this change I hadn鈥檛 experienced a blog pod install issue, and reverting to earlier commits which had built fine exhibited the same issue.
In global git I had changed autocrlf to true. Removing this config line entirely meant RN 0.61.5 and glog 0.3.4 built and installed without an issue again.
Hope this helps someone else!

I started experiencing the above issue a few weeks ago, wanted to post on here as I narrowed it down to a git config change I made on OSX.
Prior to this change I hadn鈥檛 experienced a blog pod install issue, and reverting to earlier commits which had built fine exhibited the same issue.
In global git I had changed autocrlf to true. Removing this config line entirely meant RN 0.61.5 and glog 0.3.4 built and installed without an issue again.
Hope this helps someone else!

This worked for me too. Thank you!

Thanks @elpardos. Updated my comment because your solution is better

@ASaputra2019 and @JohnpeterDairianadan, you should check elpardos' comment and the update to mine

Thanks @elpardos. Updated my comment because your solution is better

@ASaputra2019 and @JohnpeterDairianadan, you should check elpardos' comment and the update to mine

Thank you EmperorEarth,
I did what you & elpardos suggested; indeed it successfully installed Cocoapods, but after changing the git config with
git config --global --add core.autocrlf input
Then when I want to run with init command : npx react-native init AwesomeProject

I hit another error from iPhone simulator:

Metro (the local dev server) is run from the wrong folder.
Check if Metro is running, stop it and restart it in the current project.
A module failed to load due to an error and AppRegistry.registerComponent wasn't called.
runApplication
AppRegistry.js:189:6

Do you know what the problem is? I tried to google it, and saw this issue 5220 but didn't really help me, I ran to another error after changing .h and .m files... Lol..
As for your prev solution, it worked just fine.

git config --global core.autocrlf input
solve for mac
https://help.github.com/en/github/using-git/configuring-git-to-handle-line-endings

On MacOS, I fixed like below. I tried other solutions, and none worked because Flipper-Glog 0.3.6 kept on overwriting with its own podspec configuration

Run pod install and encounter error regarding Flipper-Glog ./configure^M bad interpreter

pod install

Install dos2unix to help convert file from dos format to unix format

brew install dos2unix

Go to cocoapods repos directory

cd $HOME/.cocoapods/repos/

Locate Flipper-Glog with find command

find . -name "Flipper-Glog"

You should see result like below or alike

./master/Specs/2/7/2/Flipper-Glog
./trunk/Specs/2/7/2/Flipper-Glog

Now modify podspec of those two repo for version of Flipper-Glog you can see in Podfile. For me, it was 0.3.6

nano ./master/Specs/2/7/2/Flipper-Glog/0.3.6/Flipper-Glog.podspec.json

Find "./configure --host arm-apple-darwin" and put the following right before it

dos2unix -f * \n

Save and do the same thing for repo "trunk" in search result above then you are good to run "pod install" again

Cheers :))

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aniss picture aniss  路  3Comments

ghost picture ghost  路  3Comments

josev55 picture josev55  路  3Comments

phongyewtong picture phongyewtong  路  3Comments

axelg12 picture axelg12  路  3Comments