React Native reports "Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>" error (solution)

React Native reports "Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>" error (solution)

Recently, when running an old RN project, the following code error was reported when running it with Xcode:

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

This is a problem after upgrading to XCode 12.5. Just add the following script to the ios/Podfile file.

post_install do |installer|
## Fix for XCode 12.5
  find_and_replace(
  "../node_modules/react-native/React/CxxBridge/RCTCxxBridge.mm",
  "_initializeModules:(NSArray<id<RCTBridgeModule>> *)modules", 
  "_initializeModules:(NSArray<Class> *)modules")
  
  find_and_replace(
  "../node_modules/react-native/ReactCommon/turbomodule/core/platform/ios/RCTTurboModuleManager.mm",
  "RCTBridgeModuleNameForClass(module))", 
  "RCTBridgeModuleNameForClass(Class(module)))"
  )
end

def find_and_replace(dir, findstr, replacestr)
  Dir[dir].each do |name|
      text = File.read(name)
      replace = text.gsub(findstr,replacestr)
      if text != replace
          puts "Fix: " + name
          File.open(name, "w") { |file| file.puts replace }
          STDOUT.flush
      end
  end
  Dir[dir + '*/'].each(&method(:find_and_replace))
end

Then, re-execute the pod install command to install it.

This is the end of this article about React Native reporting Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>> error (solution). For more relevant React Native error content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Summary of react basics
  • Detailed explanation of data transmission between React parent components and child components
  • Detailed explanation of the role of key in React
  • React entry-level detailed notes

<<:  Detailed explanation of top command output in Linux

>>:  Tips for data statistics in MySQL

Recommend

MySQL trigger definition and usage simple example

This article describes the definition and usage o...

Discussion on more reasonable creation rules for MySQL string indexes

Preface Regarding the use of MySQL indexes, we ha...

Optimizing query speed of MySQL with tens of millions of data using indexes

1. The role of index Generally speaking, an index...

MySQL series 15 MySQL common configuration and performance stress test

1. Common MySQL configuration All the following c...

MySQL partition table is classified by month

Table of contents Create a table View the databas...

Example code for implementing background blur effect with CSS

Is it the effect below? If so, please continue re...

How to find and delete duplicate records in MySQL

Hello everyone, I am Tony, a teacher who only tal...

Detailed explanation of virtual DOM and diff algorithm in react

The role of virtual DOM First of all, we need to ...

Learn SQL query execution order from scratch

The SQL query statement execution order is as fol...

Sample code for implementing interface signature with Vue+Springboot

1. Implementation ideas The purpose of interface ...

Linux Domain Name Service DNS Configuration Method

What is DNS The full name of DNS is Domain Name S...

Vue encapsulation component tool $attrs, $listeners usage

Table of contents Preface $attrs example: $listen...

Solve the problem of resetting the Mysql root user account password

Problem description: The following error message ...

How to check PCIe version and speed in Linux

PCIE has four different specifications. Let’s tak...