How to Solve React Native Build Failed on M1 Macbook Pro / Air
Tags: reactnative, javascript, react, mobile
Published: 2021-06-27 19:13:00


Apple has just released its newest Macbook series using Apple's M1 chip. It offers better speed, both in performance and battery life.

In this case, developers are interested in flocking to replace their old MacBook with the M1 chip. However, in addition to the advantages of the MacBook Pro M1, there are shortcomings in terms of application development. Some applications are not yet compatible with this Apple M1 chip.

## How to Set up, Build, and Run a React Native App on Macbook Pro M1 Chip

React Native is a JavaScript framework that allows native iOS and Android applications to be rendered. It makes creating two applications on different platforms more straightforward with one source code. One of the difficulties faced in developing React Native applications through MacBook Pro / Macbook Air with this M1 chip is when we want to build/run the application.

Many developers have experienced failure building react native applications through this MacBook M1.
However, don't worry because I will share tips for you to deal with errors when making an iOS application on a MacBook Pro or MacBook Air M1 Apple Silicon chip.

![Set up an M1 MacBook Pro for React Native](https://handi.dev/_next/image?url=%2Fstatic%2Fimages%2Freact-native-error-macbook-m1.png&w=3840&q=75)
 

## React Native Build Failed on Macbook Pro M1
maybe you are unable to run react-native run-ios on M1 Macbook. The error output that you will get when you build react native iOS is as below:

```bash
The following build commands failed:
CompileC /Users/[username]/Library/Developer/Xcode/DerivedData/reactNativeBoilerplate-atkaxzsfrfdlfocjvyvemwywinew/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper-Folly.build/Object. Users/[username]/[folder-path]/ios/Pods/Flipper-Folly/folly/synchronization/DistributedMutex.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
```
<Image src="/static/images/react-native-error-macbook-m1.png" alt="react native build failed on m1 mac"  layout="responsive"  width={340} height={106} />

### Solution to Run and Build React Native on M1 Macbook Pro

The solution to React Native build failure on M1 Macbook is to use Rosetta. What is rosetta? 
> [Rosetta](https://en.wikipedia.org/wiki/Rosetta_(software)) is a dynamic binary translator developed by Apple Inc. for macOS, an application compatibility layer between different instruction set architectures. It gives developers and consumers a transition period to update their application software to run on newer hardware by "translating" it to run on the different architecture.

If you're using a MacBook Pro/Air with an M1/Apple silicon chip, you might be asked to install Rosetta to open an app.

![rosetta](https://handi.dev/_next/image?url=%2Fstatic%2Fimages%2Fasking-install-rosetta-macbook.jpg&w=828&q=75)
 
1. `Set Terminal App to use Rosetta`:.
Select the app in Finder. Applications/Utilities/Terminal (App terminals). 
From the File menu in the menu bar, choose Get Info.
Make a checklist on: ( Open Using Rosetta ). See the image below.

![setting rosetta for terminal](https://handi.dev/_next/image?url=%2Fstatic%2Fimages%2Fterminal-mac-os-rosetta.png&w=750&q=75)

2. `Set Xcode to use Rosetta`:.
Select the Xcode app in Finder. Applications/Xcode (Xcode App). 
From the File menu in the menu bar, choose Get Info.
Make a checklist on ( Open Using Rosetta )

![setting rosetta for xcode](https://handi.dev/_next/image?url=%2Fstatic%2Fimages%2Fxcode-rosetta.png&w=750&q=75)

3. Delete the necessary folders so the build process can be successful and smooth.
    - delete the Pods/ folder in  your-project-dir/ios/Pods
    - delete podfile.lock in -> your-project-dir/ios/Podfile.lock

4. If you use the old code of React Native, or if you experience an error like what I said the first time, you can follow the next steps below. However, if you've just built react Native init on your MacBook M1, that shouldn't be a problem, and you should be able to build the React native ios on your MacBook smoothly.

5. The next step is to modify the Podfile in the iOS folder. your-project-dir/ios/Podfile. navigate to your react native project, and open it in the editor.

Find code below: ( your-project-dir/ios/Podfile )

```bash
use_flipper!()
```
And, replace with: 

```bash
use_flipper!({ 'Flipper-Folly' => '2.5.3', 'Flipper' => '0.75.1', 'Flipper-RSocket' => '1.3.1' })
```
 

6. The next step, install React native project as usual. Navigate to the root project directory, and run:
```bash
npx pod-install
 ```

7. Next, run npx react-native run-ios from your terminal.
```bash
npx react-native run-ios
 ```


![build react native on MacBook m1 success](https://handi.dev/_next/image?url=%2Fstatic%2Fimages%2Fsuccess-build-react-native-macbook-pro-m1-chip.png&w=3840&q=75)
 

The above method should be smooth and run well on iOS Emulator. Good Luck!
original article: [handi.dev](https://handi.dev/blog/how-run-react-native-on-macbook-m1-apple-silicon)

read also: [React Native Scaler: Perfecting App Aesthetics Across Multiple Devices ](https://dev.to/handipriyono/react-native-scaler-perfecting-app-aesthetics-across-multiple-devices-3a52)