Table of contents

Cannot initialize a parameter of type 'NSArray<id<RCTBridgeModule>> *' with an rvalue of type

React Native Nov 15, 2021 Viewed 2.3K Comments 0

Issue

I upgraded my Mac to macOS Big Sur 11.6 and Xcode to 13.0. When I opened the React Native project in Xcode, an error occurred:

/Volumes/develop/node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm:331:34: Cannot initialize a parameter of type 'NSArray<id<RCTBridgeModule>> *' with an rvalue of type 'NSArray<Class> *'

/Volumes/develop/node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm:776:79: Cannot initialize a parameter of type 'NSArray<Class> *' with an lvalue of type 'NSArray<id<RCTBridgeModule>> *__strong'

/Volumes/develop/node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm:827:69: Cannot initialize a parameter of type 'NSArray<id<RCTBridgeModule>> *' with an lvalue of type 'NSArray<Class> *__strong'

/Volumes/develop/node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm:331:34: Cannot initialize a parameter of type 'NSArray<id<RCTBridgeModule>> *' with an rvalue of type 'NSArray<Class> *'

/Volumes/develop/node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm:776:79: Cannot initialize a parameter of type 'NSArray<Class> *' with an lvalue of type 'NSArray<id<RCTBridgeModule>> *__strong'

/Volumes/develop/node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm:827:69: Cannot initialize a parameter of type 'NSArray<id<RCTBridgeModule>> *' with an lvalue of type 'NSArray<Class> *__strong'

package.js:

react: 16.11.0
react-native: 0.62.2

Solution

Fixed by changing a parameter cast like so:

1. node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm

Probably on line 771, change the code from

- (NSArray<RCTModuleData *> *)_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules
                               withDispatchGroup:(dispatch_group_t)dispatchGroup
                                lazilyDiscovered:(BOOL)lazilyDiscovered

to

- (NSArray<RCTModuleData *> *)_initializeModules:(NSArray<Class> *)modules
                               withDispatchGroup:(dispatch_group_t)dispatchGroup
                                lazilyDiscovered:(BOOL)lazilyDiscovered

2. node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm

diff --git a/node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm b/node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm
index 841f925..24f85ef 100644
--- a/node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm
+++ b/node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm
@@ -304,7 +304,7 @@ - (void)notifyAboutTurboModuleSetup:(const char *)name
             @"%@ has no setter or ivar for its bridge, which is not "
              "permitted. You must either @synthesize the bridge property, "
              "or provide your own setter method.",
-            RCTBridgeModuleNameForClass(strongModule));
+            RCTBridgeModuleNameForClass([strongModule class]));
       }
     }
Updated Dec 23, 2021