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

  1. react-native -v: 0.45.1 / cli 2.0.1
  2. node -v: v7.9.0
  3. npm -v: 5.0.3
  4. yarn --version (if you use Yarn): 0.24.6

Then, specify:

  1. Target Platform: iOS
  2. Development Operating System: macOS Sierra
  3. Build tools: any supported Xcode version, any supported iOS version

Steps to Reproduce

  1. Execute react-native init testproject
  2. 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

Most upvoted comments

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:

<key>NSAppTransportSecurity</key>
<dict>
	<key>NSAllowsArbitraryLoads</key>
	<true/>
	<key>NSAllowsArbitraryLoadsInWebContent</key>
	<true/>
	<key>NSAllowsLocalNetworking</key>
	<true/>
	<key>NSExceptionDomains</key>
	<dict/>
</dict>

Now it’s already a month ago, so not really sure how I fixed it. But I think it was by adding React to the Target 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 lines

Can it be ok like this?

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSAllowsArbitraryLoadsInWebContent</key>
    <true/>
    <key>NSAllowsLocalNetworking</key>
    <true/>
    <key>NSExceptionDomains</key>
		<dict>
			<key>localhost</key>
			<dict>
				<key>NSExceptionAllowsInsecureHTTPLoads</key>
				<true/>
			</dict>
		</dict>
</dict>

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 use npm 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.

screen shot 2018-07-16 at 23 11 02

@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 under Build 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:

NSNumber *aString = dictionary[@"key"];
[aString unsignedIntValue];

Basically, you are assigning a value with type id as an NSNumber, and using NSNumber APIs, when in fact, it’s an NSString object, which doesn’t support NSNumber selectors.