react-native: RCTCxxModule incorrectly flagged as not exported module by RCTVerifyAllModulesExported
Is this a bug report?
Yes
Have you read the Bugs section of the Contributing to React Native Guide?
Yes
Environment
react-native -v
: 0.45.1 / cli 2.0.1node -v
: v7.9.0npm -v
: 5.0.3yarn --version
(if you use Yarn): 0.24.6
Then, specify:
- Target Platform: iOS
- Development Operating System: macOS Sierra
- Build tools: any supported Xcode version, any supported iOS version
Steps to Reproduce
- Execute
react-native init testproject
- Open the Xcode project and hit run
Expected Behavior
No warnings should be logged to the Xcode console since we have the default setup.
Actual Behavior
In the Xcode log there is a warning about the RCTCxxModule
not being exported:
2017-07-03 11:09:47.963 [warn][tid:main][RCTBridge.m:114] Class RCTCxxModule was not exported. Did you forget to use RCT_EXPORT_MODULE()?
2017-07-03 11:09:47.963285+0200 testproject[467:119661] Class RCTCxxModule was not exported. Did you forget to use RCT_EXPORT_MODULE()?
Reproducible Demo
Any newly created React-Native project using the CxxBridge has this issue.
Possible solution
The RCTVerifyAllModulesExported
function uses the objc_copyClassList
which also reports the RCTCxxModule
. This triggers the warning that this module is not exported, but since the RCTCxxModule
is merely a base class that can be used by real module implementation this is a false positive.
A possible solution would be to make an exception in RCTVerifyAllModulesExported
for the RCTCxxModule
so it will not be checked and the warning will not be produced.
Note: The warning will disappear when you create a module that subclasses RCTCxxModule
since there is a check in place for that scenario. As long as there is no subclass yet this warning will pop up.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 66
- Comments: 28 (2 by maintainers)
Commits related to this issue
- Fix "Class RCTCxxModule was not exported" #14806 — committed to chrisballinger/react-native by chrisballinger 6 years ago
- Suppress spurious warning about RCTCxxModule (#19880) Summary: <!-- Required: Write your motivation here. If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue whe... — committed to macdoum1/react-native by douglowder 6 years ago
- Suppress spurious warning about RCTCxxModule (#19880) Summary: <!-- Required: Write your motivation here. If this PR fixes an issue, type "Fixes #issueNumber" to automatically close the issue whe... — committed to facebook/react-native by douglowder 6 years ago
this issue puzzle me a lot. My project ran smoothly days before, however this issue happens today, and this issue appears in every project inited by react-native-cli without any modification .
I solved this by making sure that
NSAppTrasnportSecurity
key in my info.plist had the correct values:Now it’s already a month ago, so not really sure how I fixed it. But I think it was by adding
React
to theTarget Dependencies
.In xcode > Build Phases > Target Dependencies > + > React > React
@warrenronsiek thanks,
can you add a screenshot of info.plist opened in the info plist editor? I’m new on Max and I’m not able to understand where to insert these linesCan it be ok like this?
Anyway, adding these lines didn’t stop warning about RCTCxxModule not exported
That
npm v5.x.x
sometimes removes packages while installing another one (very annoying bug, probably because we usenpm i --save module
, and npm v5 doesn’t need--save
flag). Also the error “Native module cannot be null.” happened to me the moment i changed the Bundle Identifier, i tried to clean build, clean DeriveData dir,npm start -- --reset-cache
. I checked all modules where linked correctly.In xcode console logs it has this particular row: Class RCTCxxModule was not exported. Did you forget to use RCT_EXPORT_MODULE()?
Right now it looks to me more like a warning 😕
@hramos Hi, yup it came suddenly. particularly appeared after installing
react-native-keychain
although I’m refactoring a lot of logic in auth and on init of application, so sometimes it comes, sometimes it doesn’t show. so, I have no idea how and what is causing this to appear. maybe bcz I am exporting async functions in action creator? … I have no idea!UPDATE: I just linked a library after installing a package from npm and
pod install
after this I see the warning again. Hope this will help.@yeomann this was fixed in https://github.com/facebook/react-native/commit/569061dd8384a86cd27719b8b068360d8379f4c3, can you confirm this is still an issue in master?
Adding
-ObjC
underBuild Settings > Other Linker Flags
solved this for me. My issue was that the app crashed on start with error message:Class RCTCxxModule was not exported. Did you forget to use RCT_EXPORT_MODULE()?
@TheRemjx01 You probably have something like:
Basically, you are assigning a value with type
id
as anNSNumber
, and usingNSNumber
APIs, when in fact, it’s anNSString
object, which doesn’t supportNSNumber
selectors.