128

I am trying to run my React Native app in XCode and I keep getting this error. I cannot figure out how to resolve the issue. Any suggestions?

Screen Shot of Error in XCode:

screenshot

Avag Sargsyan
  • 2,437
  • 3
  • 28
  • 41
FilosoferKing
  • 1,283
  • 2
  • 9
  • 8
  • I would suggest before applying any changes just clean your project and try to run it because same thing happen in my case. I just clean my project and run it and it works. – bittu Mar 28 '18 at 05:52
  • You should definitely change the right answer! @mark 's answer is the right one and everyone comes for it. – Serdar D. Nov 08 '19 at 22:27

26 Answers26

249

xcode Product->Scheme->Manage Schemes click '+' at the Target to select "React" and set the React is shared.

mark
  • 2,507
  • 2
  • 9
  • 2
  • 12
    I hit '+' and there is no "React" to select. A dialog comes up with "Target: MyApp" and Name: MyApp." Nothing says React or shared. – Pete Alvin Oct 08 '17 at 20:05
  • This happened to me after installing cocopods which created an xcworkspace file. My existing xcodeproj did not have "React" as an option but the xcworkspace did. – AdamG Nov 23 '17 at 15:53
  • @PeteAlvin i ran Run "npm install -g react-native-git-upgrade followed by "react-native-git-upgrade" and then it showed the react option for me – Paul Fitzgerald Dec 13 '17 at 13:32
  • 1
    After I did that Build Succeeded, but Run is not active in Xcode after that – Lucky_girl Feb 04 '18 at 12:25
  • Thanks a ton. I wonder why this is not the accepted solution. – Gaurav Grover Jun 12 '19 at 10:06
66

Delete node modules, then run npm install (or better yet yarn) and after everything has finished downloading, run react-native upgrade which should give you the option to replace old files with the template ones, by doing so you re-link your native dependencies in react-native which should fix your problem. Of course don't forget to clean your project in Xcode.

mickeymoon
  • 4,820
  • 5
  • 31
  • 56
  • 6
    You can use the new upgrade tool based on Git as it resolved conflicts automatically. Run "npm install -g react-native-git-upgrade" followed by "react-native-git-upgrade". – bitsand Jan 10 '17 at 18:08
  • 2
    I followed suggestions but nogo.. i have react-native version 0.41.2 is there anybody who is able to fix this on version 0.41.2? thanks. – joemalski Feb 26 '17 at 06:58
  • 2
    this also did not work for me. using xcode 8.2.1 and react native 0.41.2 – Terry Ray Mar 14 '17 at 17:16
  • 1
    I tried this, and it blew away some important project settings. I'm building an Action Extension, and after running `react-native upgrade` all my build settings were deleted. – Shane O Sullivan Sep 09 '17 at 05:31
  • @ShaneOSullivan use git to avoid those kind of problems. :) – Abner Terribili Sep 11 '17 at 23:00
  • 1
    i would add 'delete the yarn.lock' file so you can use 'npm install' – user1709076 Nov 28 '17 at 21:59
  • 1
    works for me. You probably forgot to close your React Packager (terminal) which is running with a different version of react native. Try to close it and restart your app again. Thanks – Saleh Masum Feb 13 '18 at 09:01
  • @SalehMasum This is what happened to me. Gotta make sure all processes connected to app are closed – thebeagle Feb 19 '18 at 00:18
19

For all those are using React Native 0.40.0 or higher, Header Imports have a major change from RN 0.40.0 and result in lots of .h file not found errors. react-native-git-upgrade fixed the issue for me while in debug but build fails in release/archive.

I am using RN 0.42.3 with cocoapods and Xcode 8.2.1

To completely fix this go to Xcode>Product>Scheme>Edit Scheme>

  1. Untick Parallelize Build enter image description here
  2. Click on + button in Targets and add React enter image description here
  3. Drag the added React to top of the List in Targets. enter image description here

Now clean the project and build

Community
  • 1
  • 1
Hariks
  • 1,852
  • 1
  • 19
  • 34
17

None of the other suggestions were fixing my error but this one did it.

1 - Create Podfile

Create a file named ios/Podfile inside your react-native app with the following contents:

# You Podfile should look similar to this file. React Native currently does not support use_frameworks!
source 'https://github.com/CocoaPods/Specs.git'

platform :ios, '8.0'

target '<YOUR_APP_NAME>' do
  # Fixes required for pod specs to work with rn 0.42
  react_native_path = "../node_modules/react-native"
  pod "Yoga", :path => "#{react_native_path}/ReactCommon/yoga"
  pod "React", :path => react_native_path, :subspecs => [
    'Core',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket'
  ]

  pod 'GoogleMaps'  # <~~ remove this line if you do not want to support GoogleMaps on iOS

# when not using frameworks  we can do this instead of including the source files in our project (1/4):
#  pod 'react-native-maps', path: '../../'
#  pod 'react-native-google-maps', path: '../../'  # <~~ if you need GoogleMaps support on iOS
end

2 - Install Podfile

Run the command pod install from inside the ios folder.

3 - Reset XCode

Restart XCode and the error should be gone.

Erich
  • 2,743
  • 1
  • 24
  • 28
  • This solves the issue to some extent. But what I found out was that new configurations do not seem to respect the build order so they are not taking custom scripts in. Fundamentally this is an issue with react-native or react-native + xcode – prog_24 Jan 02 '18 at 10:45
9

The solution that works for me is to share React scheme.

If you don't have React scheme, create new one by Selecting scheme menu -> Manage Scheme -> + -> choose React, then mark React scheme as Shared

enter image description here

enter image description here enter image description here

Also, if you use Xcode 10, go to File -> Project Settings and select Legacy build system

enter image description here

onmyway133
  • 45,645
  • 31
  • 257
  • 263
8

I ran into this problem after my first try running a React build in XCode, and all I had to do was actually build and run to make the error go away (after picking a team and proper provisioning). Sometimes XCode shows errors that aren't really errors until it compiles and links things the first time.

Dave Cole
  • 2,446
  • 2
  • 20
  • 26
7

I solved this problem by following steps:

  1. In xcode choose project root.
  2. Drag React.xcodeproj from Libraries to the root of the project.
  3. Click on project name (in my case it name SaleKit) in TARGETS
  4. Choose Build Phases
  5. In dropdown of Target Dependencies add React
  6. Rebuild or re-run

enter image description here

Robust
  • 2,415
  • 2
  • 22
  • 37
  • 1
    This worked for me! I use react-native-schemes-manager, and so it was my Staging scheme that wouldn't build until I added this. It worked previously for months, then suddenly didn't after a fresh clone. Suspect my NPM ranges in package.json are too generous. –  Dec 18 '17 at 20:59
  • Worked for me, without the need to drag React.xcodeproj out of Libraries folder. – ErmannoS Apr 03 '18 at 15:43
  • Any ideas if there is no dependency `react` listed? – four-eyes Oct 17 '21 at 11:05
6

For my case in ReactNative "0.54.2", i solved it with following solution

In Xcode select Product->Scheme->Manage Schemes, untick 'YourProject'-tvOS set it to not Shared

JXLai
  • 312
  • 4
  • 10
5

Best Solution :

Open 'Build Settings' for your project in Xcode , search 'Header Search Path'.

Double click next to 'Header Search Path', where other properties have a 'yes' or 'no'

Now add following to the "Header Search Path" (under Build Settings):

$(SRCROOT)/../node_modules/react-native/React
$(SRCROOT)/../node_modules/react-native/React/Base

Don`t forget Make both of them recursive.

Mega Area
  • 101
  • 1
  • 4
4

You might be running .xcodeproj file after pod is installed.

Close it and open .xcworkspace file. It worked for me.

Saranjith
  • 11,242
  • 5
  • 69
  • 122
2

In the base dir of the project I run:

node_modules/react-native/packager/packager.sh --reset-cache

Which resulted in:

Scanning 554 folders for symlinks in /Users/..../work/..../react_tutorial/AwesomeProject/node_modules (15ms)
 ┌────────────────────────────────────────────────────────────────────────────┐
 │  Running packager on port 8081.                                            │
 │                                                                            │
 │  Keep this packager running while developing on any JS projects. Feel      │
 │  free to close this tab and run your own packager instance if you          │
 │  prefer.                                                                   │
 │                                                                            │
 │  https://github.com/facebook/react-native                                  │
 │                                                                            │
 └────────────────────────────────────────────────────────────────────────────┘
Looking for JS files in
   /Users/..../work/...../react_tutorial/AwesomeProject

Loading dependency graph... ERROR  Packager can't listen on port 8081
Most likely another process is already using this port
Run the following command to find out which process:

lsof -i :8081

I found that package manager can't run when another packager process is running.

I found the process running with:

lsof -i :8081

Than I kill 9 ... the process.

After than I closed Xcode, run:

npm install

And started Xcode again, from this moment everything work as expected!!

Oded Regev
  • 4,065
  • 2
  • 38
  • 50
2

Try the following:

  1. Clean (cmd+shift+K).
  2. Build core React - select React as the scheme in Xcode and build it (cmd+B).
  3. Build the library that is failing (e.g. RCTText).
  4. Build your app.
Cœur
  • 37,241
  • 25
  • 195
  • 267
jyson
  • 21
  • 1
  • 2
2

I had the same issue and I fixed it by placing RNFIRMessaging.h above the React/RCTBundleURLProvider.h

So it look I will look like:

#import "AppDelegate.h"
#import "RNFIRMessaging.h"

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
Jefferson Filho
  • 91
  • 1
  • 12
2

click Product->Scheme->Manage Schemes->+ . and then add react as shared. also insure that your project name is there too.

Eran Or
  • 1,252
  • 15
  • 22
1

I faced same issue .then i have deleted node .try to use these steps

  1. Delete the node_modules folder - rm -rf node_modules && npm install
  2. Reset packager cache - rm -fr $TMPDIR/react-* or node_modules/react-native/packager/packager.sh --reset-cache
  3. Clear watchman watches - watchman watch-del-all

then make build and see

Sport
  • 8,570
  • 6
  • 46
  • 65
1

I found that my fix to this issue after upgrading React was to change the declaration of #import "RCTBundleURLProvider.h" to #import <React/RCTBundleURLProvider.h>

ays0110
  • 240
  • 4
  • 18
1

Run npm install in your project directory to install react-native resolving this error.

Paul Brittain
  • 319
  • 2
  • 17
1

For me replacing

#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>

by

#import <RCTBundleURLProvider.h>
#import <RCTRootView.h>

in AppDelegate.m file worked.

Pankti Shah
  • 337
  • 6
  • 20
0

If you havent run npm install you are likely to encounter this issue.

Harkirat Saluja
  • 7,768
  • 5
  • 47
  • 73
0

I have gone through all the answers mentioned above.

Here is the solution worked for me:

STEP 1:

Run:

npm install react-native-fcm --save 

This result in making the directory in your project under node_modules > react-native-fcm

Add react-native-fcm to your project

STEP 2:

You need to add '$(SRCROOT)/../node_modules/react-native-fcm/ios' to header search paths in build settings.

Add to header search paths

These 2 steps worked for me to remove the error.

For more details you can go through these links:

https://github.com/evollu/react-native-fcm/issues/63

https://github.com/evollu/react-native-fcm/issues/21

piet.t
  • 11,718
  • 21
  • 43
  • 52
Harjot Singh
  • 6,767
  • 2
  • 38
  • 34
0

For my case, I couldn't delete node_modules and re-install and I also couldn't do react-native-git-updgrade or react-native upgrade because I wanted to stay on RN-0.59 because .60 causes problems for my dependencies.

Anyway my situation was that I was missing 'React/RCTBundleURLProvider.h' file. I already had React available in my schemas. It was not in my libraries directory. I checked my target's build settings.

Inside target dependencies, I also had React in there.

I deleted 'React' target dependency, then re-added. cleaned build folders, re-built project. it worked.

Jim
  • 1,988
  • 6
  • 34
  • 68
0

I am using React Native 0.61. I created a Share Extension and was getting this error. I needed to replace:

#import "RCTBundleURLProvider.h"

with

#import "React/RCTBundleURLProvider.h"
Eric Wiener
  • 4,929
  • 4
  • 31
  • 40
0

https://github.com/facebook/react-native/blob/v0.63.3/template/ios/Podfile

Find/Replace HelloWorld with your your project name.

Place this file into the ./ios folder in your project

gem install cocoapods
cd ios
pod install

Then open the YourProject.xcworkspace file in XCode

in XCode, go to Product -> Scheme -> Manage Schemes and check React

Then try building the project again.

FreePender
  • 4,770
  • 2
  • 18
  • 15
-1

I tried all the suggestions and none of them worked at the i deleted the repo and clone it again and that work for me, so my suggestion is commit your changes back them up and clone the repo again that worked for me.

ragar90
  • 78
  • 9
-2

you need to install react native, in terminal run

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

then

brew install node
brew install watchman
npm install -g react-native-cli

source:
https://facebook.github.io/react-native/docs/getting-started.html

Olzh
  • 123
  • 3
-3

Make sure that the path to your project don't have any spaces. Just renaming folders and deleting spaces solves the problem for me.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
user5807443
  • 311
  • 3
  • 3