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

Vue.js implements tab switching and color change operation explanation

When implementing this function, the method I bor...

Troubleshooting the cause of 502 bad gateway error on nginx server

The server reports an error 502 when synchronizin...

IE6 space bug fix method

Look at the code: Copy code The code is as follows...

Using Vue to implement timer function

This article example shares the specific code of ...

CSS hacks \9 and \0 may not work for hacking IE11\IE9\IE8

Every time I design a web page or a form, I am tr...

JavaScript's unreliable undefined

undefined In JavaScript, if we want to determine ...

Prevent HTML and JSP pages from being cached and re-fetched from the web server

After the user logs out, if the back button on the...

HTML form_PowerNode Java Academy

1. Form 1. The role of the form HTML forms are us...

Detailed explanation of Docker Swarm service orchestration commands

1. Introduction Docker has an orchestration tool ...

Vue installation and use

Table of contents 1. Vue installation Method 1: C...

Nginx restricts IP access to certain pages

1. To prohibit all IP addresses from accessing th...

A brief discussion on Linux virtual memory

Table of contents origin Virtual Memory Paging an...

Docker uses root to enter the container

First run the docker container Run the command as...