148

Getting this error while building a react-native iOS app on xcode.

enter image description here

Started getting this error after npm install and rpm linking react-native-fs library. But after searching online for a solution, I noticed that many people are getting the same error while installing other react native libraries.

A possible solution suggested by many is, Adding the following under "Build Settings" -> "Header Search Paths".

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

But no luck with this solution, still getting the same error

Simar
  • 2,475
  • 5
  • 16
  • 19

25 Answers25

169

In my case this particular problem happened when I was trying to archive a 0.40+ react-native app for iOS (solution was found here: Reliable build on ^0.39.2 fails when upgrading to ^0.40.0).

What happened was that Xcode was trying to build the react-native libraries in parallel and was building libraries with implicit react dependencies before actually building the react library.

The solution in my case was to:

  1. Disable the parallel builds:

    • Xcode menu -> Product -> Scheme -> Manage Shemes...
    • Double click on your application
    • Build tab -> uncheck Parallelize Build
  2. Add react as a project dependecy

    • Xcode Project Navigator -> drag React.xcodeproj from Libraries to root tree
    • Build Phases Tab -> Target Dependencies -> + -> add React
Edgar
  • 6,022
  • 8
  • 33
  • 66
agiaLab
  • 1,855
  • 1
  • 12
  • 6
36

Make sure you disable Parallelise Build and add React target above your target

enter image description here

onmyway133
  • 45,645
  • 31
  • 257
  • 263
  • Figured it out on my own after the first answer, but moving react up did the trick! Had to realize what that actually meant for the building process though – njoye Sep 26 '18 at 19:15
  • 1
    Was pulling my hair out and thinking what I was doing wrong after adding the React target but moving it up did the trick. @njoye could you explain what this means in the build process? Thank you! – Eugene Kim Oct 30 '18 at 05:58
  • @EugeneKim the order of elements in lists is Apple's way of showing chronological order (this still f*s me up often, on OSX as well as iOS). So putting the target "React" before "App" will build the code from "React" before your own. Since your own code uses the React target this seems to affect if it is able to be built. There are probably files being built that are then used in your target. – njoye Nov 12 '18 at 17:31
  • I want to use the parallel build feature to reduce the build time – utkarsh-devops Jul 30 '19 at 09:06
30

QUICK FIX (not the best)

Change the import react-native header lines:

 #import <React/RCTBridgeModule.h>
 #import <React/RCTLog.h>

To:

 #import "RCTBridgeModule.h"
 #import "RCTLog.h"

Here is an example of changes I had to make for the library I was trying to use: Closes #46 - 'RCTBridgeModule.h' file not found.

Iso
  • 3,148
  • 23
  • 31
Simar
  • 2,475
  • 5
  • 16
  • 19
  • 18
    If you read the release notes carefully, I think it's actually the other way -- the new / approved way is `#import `? [commit here](https://github.com/facebook/react-native/commit/e1577df1fd70049ce7f288f91f6e2b18d512ff4d) – user Jan 25 '17 at 15:29
  • 2
    I know it seems backwards to what the docs recommend, but the specified format `#import "RCTBridgeModule.h"` really did work better for me today. – paws Mar 16 '17 at 00:02
  • The error for me is flagged in the file RCTFileReaderModule.h. I changed the #import statement as suggested but it didn't help. I see in the linked repo pull request that the change was done in RNFSManager.h and RNFSManager.m. I tried making it in these two files but it didn't help either. Any idea what I am doing wrong? – Yossi Apr 27 '20 at 07:21
  • 1
    But my code is erroring out at `#import "RCTBridgeModule.h"`... – velkoon Aug 26 '21 at 19:19
  • [0.71] Do not use this method, all subsequent imports inside `React/*.h` now fails with not found. – Vicary Jan 26 '23 at 09:01
15

Change

  #import "RCTBridgeModule.h"

to

 #import "React/RCTBridgeModule.h"
4

If Libraries/React.xcodeproj are red in xcode then reinstall node_modules

rm -rf node_modules && yarn

My newly created project from react-native 0.46.3 was red :S I have npm 5.3.0 and yarn 0.24.5 when I did react-native init

Codler
  • 10,951
  • 6
  • 52
  • 65
  • Thank you, i was pushing my project to github. And when cloning it again i was missing the React libraries that were showing in red. your command is working. – Rifinio Jan 16 '18 at 16:04
4

For me, this error occurred when I added a new scheme/target (app.staging) in the app and installed pods using pod install.

This issue is occurring due to pods are not shared for all targets. So I need to add newly added target (app.staging) inside the Podfile.

Here is my Podfile.

platform :ios, '9.0'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'

target 'app' do
  # Pods for app
  pod 'FBLazyVector', :path => "../node_modules/react-native/Libraries/FBLazyVector"
  pod 'FBReactNativeSpec', :path => "../node_modules/react-native/Libraries/FBReactNativeSpec"

  target 'appTests' do
    inherit! :search_paths
    # Pods for testing
  end

  # Pods for staging app // important line below
  target 'app.staging'

  use_native_modules!
end
Maulik Dhameliya
  • 1,470
  • 1
  • 17
  • 21
4

I ran into this issue after doing a manual react-native link of a dependency which didn't support auto link on RN 0.59+

The solution was to select the xcodeproj file under the Libraries folder in Xcode and then in Build Settings, change Header Search Paths to add these two (recursive):

$(SRCROOT)/../../../ios/Pods/Headers/Public/React-Core
$(SRCROOT)/../../../ios/Pods/Headers/Public
qwertzguy
  • 15,699
  • 9
  • 63
  • 66
  • 1
    this solved my problem, I think the old solutions(linking React.xcodeproj etc) don't work anymore, this one is the correct solution. – Tarun Gupta Apr 02 '22 at 16:44
  • 1
    That worked for me too, wasted some time on this one.. Should be the selected answer in 2022 when humanity divided to projects in > 0.59 and < 0.59 – Blue Bot Oct 25 '22 at 16:46
3

For viewers who got this error after upgrading React Native to 0.40+, you may need to run react-native upgrade on the command line.

Lawrence
  • 10,142
  • 5
  • 39
  • 51
  • 5
    I'm trying this right now. What about using [react-native-git-upgrade](https://github.com/facebook/react-native/tree/master/react-native-git-upgrade) instead? – pgarciacamou Feb 21 '17 at 17:32
  • Right, that's the other option. I think they'll both work. – Lawrence Feb 21 '17 at 21:12
3

My solution was to remove everything in Libraries like described here

redexp
  • 4,765
  • 7
  • 25
  • 37
  • This worked for me, thank you so much! By the way, @redexp if possible can you please explain what was the issue exactly? Because I have no idea about cocoapods and xcode – Shubham Bisht Apr 22 '22 at 15:39
2

Latest releases of react-native libraries as explained in previous posts and here have breaking compatibility changes. If you do not plan to upgrade to react-native 0.40+ yet you can force install previous version of the library, for example with react-native-fs:

npm install --save -E react-native-fs@1.5.1
Max Vorobjev
  • 1,233
  • 6
  • 7
2

I was able to build a debug, but I was unable to build an archive.

I solved this issue by dragging React.xcodeproj found in /node_modules/react-native/React to my root directory in Xcode, then added React as a target dependancy in build phases > target dependencies.

BuffMcBigHuge
  • 579
  • 5
  • 8
2

After React Native 0.60 this issue is often caused by a linked library mixed with the new 'auto-linking' feature. This fixes it for me

Unlink old library using

$ react-native unlink react-native-fs

Refresh Pods integration entirely using

$ pod deintegrate && pod install

Now reload your workspace and do a clean build.

Peter Theill
  • 3,117
  • 2
  • 27
  • 29
2

I receive this error in any new module I create with create-react-native-module. None of the posted solutions worked for me.

What worked for me was first making sure to run yarn in the newly created module folder in order to create node_modules/ (this step is probably obvious). Then, in XCode, select Product -> Scheme -> React instead of the default selection of MyModuleName.

Taylor Kline
  • 908
  • 3
  • 9
  • 30
  • +1, it's important to add for others new to module development that you won't see the other schemes until you create a valid podfile and run `pod install`. create-react-native-module does not appear to do this for you. Got me hung up for a while. But this worked for me once I created a valid podfile and ran the install. – Elliot Rodriguez Feb 15 '20 at 13:44
  • @ElliotRodriguez is the Podfile from the example/ios folder acceptable for a library itself? – Vyacheslav Orlovsky Aug 07 '22 at 10:40
2
  • delete the pods folder and the .xcworkspace file
  • run pod install again in that directory
  • try to archive again and done
FaysalB
  • 330
  • 1
  • 11
1

This error appeared for me after I ran pod install command for the new dependencies. Along with those, React had also been installed. Therefore probably Xcode was confused for path. I removed these lines from PodFile and error was gone. Please note that those removed from here were already linked in Xcode.

target 'app' do

  pod 'GoogleMaps'
  pod 'Firebase/Auth', '~> 6.3.0'
  pod 'Firebase/Database', '~> 6.3.0'

  # Removed four pods below and it worked.

  pod 'react-native-image-picker', :path => '../node_modules/react-native-image-picker'

  pod 'ReactNativePermissions', :path => '../node_modules/react-native-permissions'

  pod 'react-native-image-resizer', :path => '../node_modules/react-native-image-resizer'

  pod 'RNFS', :path => '../node_modules/react-native-fs'

  end
NightFury
  • 13,436
  • 6
  • 71
  • 120
1

Go to iOS folder in your project and install pod -

$ pod install

If you are getting any error in installation of pod type command-

$ xcode-select -p

Result should be - /Applications/Xcode.app/Contents/Developer

If the path is incorrect then open your iOS project in Xcode and go to: Xcode->preferences->command line tools-> select Xcode

And again install the pod your issue will be fixed.

Ajeett
  • 814
  • 2
  • 7
  • 18
Ujjwal Singh
  • 124
  • 9
1

anhdevit's suggestion in https://github.com/facebook/react-native/issues/24363#issuecomment-488547280 worked for me:

In your terminal, run: defaults delete com.apple.dt.Xcode

Yossi
  • 5,577
  • 7
  • 41
  • 76
0

If you want to make it from your editor also open SMobile.xcscheme

And change parallelizeBuildables = "NO"

Hadnazzar
  • 1,517
  • 19
  • 21
0

For me didn't work any from the above solutions and below it is what worked (I had already checked out Parallelize Build and added React)

1. Open XCode --> To Libraries add `$LibraryWhichDoesNotWork.xcodeproj$`
2. Then for your app in the `Build Phases` add to the `Link Binary with Libraries` the file `lib$LibraryWhichDoesNotWork$.a`
kodeusz
  • 178
  • 3
  • 10
0

I've encountered this issue while upgrading from 0.58.4 to new react-native version 0.60.4. Nothing from what i found on the internet helped me, but I managed to get it working:

Go to build settings, search for 'Header search paths', select the entry, press DELETE button.

I had these values overriden, and looks like they fell back to defaults after deletion. Also Cocoapods was complaining about it with messages in Terminal after pod install:

[!] The `app [Release]` target overrides the `HEADER_SEARCH_PATHS` build setting defined in `Pods/Target Support Files/Pods-app/Pods-app.release.xcconfig'. This can lead to problems with the CocoaPods installation
Hlib Barylskyi
  • 865
  • 1
  • 7
  • 11
0

If you want to keep Parallelise Build enabled and avoid the missing header problems, then provide a pre-build step in your scheme to put the react headers into the derived-data area. Notice the build settings are coming from the React project in this case. Yes it's not a thing of beauty but it gets the job done and also shaves a lot of time off the builds. The prebuild step output ends up in prebuild.log. The exact headers you'll need to copy over will depend on your project react-native dependencies, but you'll get the jist from this.

Edit Scheme => Build

Get the derived data directory from the environment variables and copy the required react headers over.

#build_prestep.sh (chmod a+x)
derived_root=$(echo $SHARED_DERIVED_FILE_DIR|sed 's/DerivedSources//1')
react_base_headers=$(echo $PROJECT_FILE_PATH|sed 's#React.xcodeproj#Base/#1')
react_view_headers=$(echo $PROJECT_FILE_PATH|sed 's#React.xcodeproj#Views/#1')
react_modules_head=$(echo $PROJECT_FILE_PATH|sed 's#React.xcodeproj#Modules/#1')
react_netw_headers=$(echo $PROJECT_FILE_PATH|sed 's#React/React.xcodeproj#Libraries/Network/#1')
react_image_header=$(echo $PROJECT_FILE_PATH|sed 's#React/React.xcodeproj#Libraries/Image/#1')

echo derived root = ${derived_root}
echo react headers = ${react_base_headers}

mkdir -p ${derived_root}include/React/

find  "${react_base_headers}" -type f -iname "*.h" -exec cp {} "${derived_root}include/React/" \;
find  "${react_view_headers}" -type f -iname "*.h" -exec cp {} "${derived_root}include/React/" \;
find  "${react_modules_head}" -type f -iname "*.h" -exec cp {} "${derived_root}include/React/" \;
find  "${react_netw_headers}" -type f -iname "*.h" -exec cp {} "${derived_root}include/React/" \;
find  "${react_image_header}" -type f -iname "*.h" -exec cp {} "${derived_root}include/React/" \;

The script does get invoked during a build-clean - which is not ideal. In my case there is one env variable which changes letting me exit the script early during a clean.

if [ "$RUN_CLANG_STATIC_ANALYZER" != "NO" ] ; then
    exit 0 
fi
O Wigley
  • 157
  • 1
  • 4
0

react-native version 0.67.4 (recently updated) This build error started to show up in ios.

I found under my project > Edit Scheme > Build

There was a reference to "React" but it indicated "Missing"

So I removed it (little - button) and added React back (little + button) via the popup which has a Pods folder and a "React" pod project present.

So it looks like react-native used to supply a project file that you would set as a build target in the scheme: /node_modules/react-native/ReactReact.xcodeproj

However with this newer version of react that project is not present, which would explain why building will fail if you have a native module bridge (its searching for header files that don't exist)

I no longer get the build error, but I haven't verified it works. Will update once I get a positive outcome (or a negative one for that matter). Even if this does fix it, I am not sure if this is the "right" way, but I'm certainly open to suggestions.

Glorifundel
  • 746
  • 1
  • 8
  • 16
0

In my case, the wrong target was selected in podfile, after correcting that, I was good to go.

Musab Gulfam
  • 126
  • 1
  • 7
0

In my case, I removed the 'arm64' from the release section located under Excluded architectures in the targets project

Kingsley Akpan
  • 213
  • 3
  • 3
-3

What you can do to get it right is:

1) npm uninstall reat-native-fs to uninstall library

2)npm unlink react-native-fs to unlink the library

Now the library is successfully removed and now install the lib again in your project and this time link everything manually. Sometime automatic linking causes this error.

Håken Lid
  • 22,318
  • 9
  • 52
  • 67
Codesingh
  • 3,316
  • 1
  • 11
  • 18