react-native: npx react-native init fails on Installing Bundler

Description

I have been trying to create a new react-native app with the command npx react-native init SamepleApp but it fails on Installing Bundler with the following issue

✖ Installing Bundler error /Library/Ruby/Site/2.6.0/rubygems.rb:265:in find_spec_for_exe’: can’t find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException) from /Library/Ruby/Site/2.6.0/rubygems.rb:284:in activate_bin_path' from /usr/bin/bundle:23:in <main>’

✖ Installing Bundler error Error: Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/next/environment-setup and follow the React Native CLI QuickStart guide for macOS and iOS. Error: Error: Looks like your iOS environment is not properly set. Please go to https://reactnative.dev/docs/next/environment-setup and follow the React Native CLI QuickStart guide for macOS and iOS. at createFromTemplate (/Users/mac/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/commands/init/init.js:169:11) at runMicrotasks (<anonymous>) at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Object.initialize [as func] (/Users/mac/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/commands/init/init.js:222:3) at async Command.handleAction (/Users/mac/.npm/_npx/7930a8670f922cdb/node_modules/@react-native-community/cli/build/index.js:140:9) info Run CLI with --verbose flag for more details.`

I tried updating my ruby version to the latest version but it also did not help. Also tried bundle install in my project by it also failed

I have been using MacBook Pro 2017 with Intel Chip and my ruby version is 2.6.10p210, Node version is v16.17.1 and no react-native-CLI is globally installed.

Version

0.70.6

Output of npx react-native info

System: OS: macOS 13.1 CPU: (8) x64 Intel® Core™ i7-7700HQ CPU @ 2.80GHz Memory: 76.06 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.17.1 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 8.15.0 - /usr/local/bin/npm Watchman: 2022.12.05.00 - /usr/local/bin/watchman Managers: CocoaPods: Not Found SDKs: iOS SDK: Not Found Android SDK: Not Found IDEs: Android Studio: 2021.1 AI-211.7628.21.2111.8193401 Xcode: /undefined - /usr/bin/xcodebuild Languages: Java: 11.0.17 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: Not Found react-native: Not Found react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

  1. Open your terminal.
  2. Run npx react-native init SampleApp
  3. Issue got reproduced

Snack, code example, screenshot, or link to a repository

Screenshot 2022-12-17 at 7 54 09 PM

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 1
  • Comments: 16

Most upvoted comments

So this is what eventually works, the bundler fails when we try to setup our barebone react native cli project using npx react-native init demo but then you cd demo and cd ios and run the command pod install to finish up what failed bundled could not at the first step. After that cd .. && npm run ios would work.

Hey @sadafliaqat2nov, I have got a solution for this issue. Follow below steps to resolve this issue:

  1. Install rbenv and install Ruby using it with rbenv install 3.1.3.
  2. After installing it set it to your global Ruby version with the command rbenv global 3.1.3.
  3. If this command does not work, try uninstalling this version and reinstalling it. This thing helped me and then I was able to set ny recent version of Ruby to global version.

Let me explain that what does rbenv global 3.1.3 or rbenv local 3.1.3 does for you. Basically it generates a .ruby-version file in your respective folder and it appends the the version 3.1.3 in it. If global command is not working for you, you can find .ruby_version file inside your installed Ruby directory and manually update it.

In case of new application, when cocoapods are being installed, React native cli is somehow unable to detect the relevant Ruby version and it fails with exceptions. This is happening after the recent upgrade of react-native version of 0.70.x. React Native cli now expects ^2.7.5 Ruby version while MaC is using 2.6.10p even in its latest OS.

Now after following my above solution, you will need to open a relevant folder in your terminal (please make sure that any of you folder does not have spaces in its name, otherwise it will lead to other issues). After that, run this command npx react-native init SampleApp

May be this command will again fail on Insalling Bundler. Just go inside your ios directory and run rbenv local 3.1.3. A .ruby_version file will be generated. Now run pod install and boom 💥 All Pods will be installed and your app will be ready.

Note: You will need to run rbenv local 3.1.3 everytime when you initialize a new react native project until this bug gets officially fixed.

Thanks!