react-native: RN 0.42.0 iOS 'Lexical Preprocessor Issue'. React header files not found.

Description

Fresh RN project initializations have been failing to build and run for me. I have been facing this issue for about a week and a half and tried several different things. I simply cannot get a React Native project to build on my machine. Header files cannot be found for whatever reason. Any help would be very appreciated.

Reproduction

react-native init testproject open Xcode project Clean project Build project Build fails

Error screenshots: screen shot 2017-03-05 at 11 29 11 pm screen shot 2017-03-05 at 11 29 18 pm

Additional Information

  • React Native version: 0.42.0
  • Platform: iOS (Xcode 8.2.1)
  • Operating System: MacOS Sierra

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 5
  • Comments: 27 (2 by maintainers)

Most upvoted comments

I tried the solution in here: https://twitter.com/skellock/status/818813810781908992, and the problem solved. Remember to disable parallelize build in scheme configuration and add React target before your own project target. Hope it helps.

Additional information: React Native version: 0.44.0 Platform: iOS (Xcode 8.3.2) Operating System: MacOS Sierra

For me - rm -rf node_modules watchman watch-del-all rm -fr $TMPDIR/react-*, restart xcode, rm -fr $TMPDIR/react-* helped.

RN-0.43.3 has the same issues. Unable to find React headers. Tried disabling the parallelize build options as well as adding React as one of build variants.But still the same.

Unfortunately the solution described there didn’t work for me.

This is obviously a problem with the libraries not finding the include paths from React. I don’t know much about Xcode and mac development and for someone from the React-Native team there might be an easy and obvious fix, but unfortunately we didn’t hear anything from them.

So by analyzing the react-native < 40 Xcode settings and trying to understand the Xcode include path system I came up with a solution that works for me:

In the Xcode project tree select the React.xcodeprj and inside select Build Phase. Then find the section Copy Header and change the Subpath to ../include/React

Now in every other Library open the project settings Build Settings. Then find the section Search Paths and set Header Search Paths to $(SRCROOT)/../../ReactCommon/** $(SRCROOT)/../../React/build/include/**

Now for the project settings of the actual project set this value to $(SRCROOT)/../node_modules/react-native/ReactCommon/** $(SRCROOT)/../node_modules/react-native/React/build/include/**

Unfortunately this fix doesn’t work the test target, so I just delete it from the product scheme: Open Product -> Scheme -> Edit Scheme… Then select Build and remove the test target.

Now building and running the project should work.

I have the same issue. I also tried the the 0.43 rc1. Just creating a new project with init and try to run on ios. All react libraries cannot resolve the paths starting with <React/…> Doesn’t work on the command line or from XCode. The last React Native version I am able to run is 0.39.2. All versions after have this issue for me. I have macOS Sierra (10.12.3) and XCode 8.2.1.

Could my XCode settings be messed up? Any help would be awesome.

I think I know why this happens. In react native < 0.40 the import path was just the filename, e.g.: #import <RCTDefines.h>

To find the includes in the header search path of the library was added <yourproject>/node_modules/react-native/React/** which means it includes all the subdirectories in this path. This way the file was found.

Now for whatever reason the team decided they need an import path that includes a React therefore since react-native 0.40 the path is: #import <React/RCTDefines.h> But if you look for the file, you will find it in the directory React/Base/RCTDefines.h. That way the old header include would not work anymore.

Now the trick to solve this is to include a Copy Header phase in the Build Phase of the React project. This copies all header files flat in a new directory. Now this directory must be called ‘React’. Now the libraries must include the path that contains this new React directory then they will find the new import path.

What puzzles me now, is that the projects created from react-native > 0.40 have this copy header phase added, but the header include path for all libraries is empty. I don’t know if the team simply forgot to make this right and nobody is testing it, or if there is another magic that should make it work and just fails for a few people like us for whatever reason.

So what you have to fix is that the path where the headers from the react project are copied to is included as header search path for each library.

Additionally you need to do what @the-ant pointed to. That is in the Scheme disable parallel build and add React at a build target before your project. This is necessary to ensure, that the headers are copied first before the other libraries are build.

What I did to solve, after trying everything described here:

Created a new project with react-native init using the same name as my actual project, copied the iOS folder to my actual project.

At first I updated the project with Xcode’s recommended settings, but have problems anyway. Tried again without applying the updates and worked, finally, fine.

This issue is dragging me for two days already. I’ve tried everything you guys mentioned here, all the Twitter/Stack Overflow screenshots, but nothing seems to work. My debug scheme is working fine, but when I switch to release it complains about lexical issue.

I’m not sure how the debug scheme works fine and release don’t.

Also, is it just me or every RN update seems to be a pain?

Here is how I fixed it.

http://stackoverflow.com/questions/42158178/react-native-base-headers-for-ios-not-found/42700452#42700452

The solution is to add a same configuration in React.xcodeproj to match the one of your project. For example, if you have “Debug/Release/Test/AppStore” 4 configurations in your own project, you have to make sure React.xcodeproj has the same 4 configurations.

please Click the “+” button of Configurations, "Duplicate Release Configuration, and rename it according to you need.

Cleaned and rebuilt again but this time got some new issues. This is after running react-native link.

screen shot 2017-03-05 at 11 59 42 pm

This time it’s <React/RCTBridge.h> inside of RCTActionSheet that can’t be found.