Help! My Module is Broken
You may have received an error message like the one below when trying to use an older React Native iOS module in the latest React Native >= 0.40.
"Duplicate interface definition for class "'RCTView'"
If you're native module was created prior to React Native version 0.40 you'll need to upgrade your module to work with the latest version of React Native.
How Do I Fix It?
- Fork the component into your own repo.
- Open the
ios/ProjectNamefolder in your new repo.
- Look through all the
.hfiles and commit the changes described below to any occurrence of an import with the RCT (RCT stands for React) prefix.
- Now you can replace the
package.jsonvalue for that component with the Github URL of your updated component in any project you want to use your fixed version of the component in.
- Be an awesome person and create a pull request on the source repo to help out the community!
Only support latest React Native:
// change this: #import "RCTView.h" // to this: #import <React/RCTView.h>
Why would you want to only support the latest? @edmundito brings up some good points on this thread:
I'm happy either way, and I've been tracking other dependent modules that need to be updated to 0.40, and there's a general pattern that I'm ok with:
- Make changes without backward compatible support
- Bump the minor number
- Update the README to denote what version is compatible with 0.39 or below.
Not recommended but if you need your module to work on both versions you can use this backwards compatible fix:
#if __has_include(<React/RCTView.h>) #import <React/RCTView.h> #elif __has_include("RCTView.h") #import "RCTView.h" #else #import "React/RCTView.h" // Required when used as a Pod in a Swift project #endif