關于React Native報Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>錯誤(解決方案)
最近,在運行一個老RN項目的時候,使用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> *'
這是由于升級XCode 12.5之后的問題,在ios/Podfile文件中加入如下的腳本即可。
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
然后,重新執(zhí)行pod install 命令安裝即可。
到此這篇關于關于React Native報Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>錯誤(解決方案)的文章就介紹到這了,更多相關React Native報錯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
- React找不到模塊“./index.module.scss”或其相應的類型聲明及解決方法
- react 報錯Module build failed: BrowserslistError: Unknown browser query `dead`問題的解決方法
- 在?React?Native?中使用?CSS?Modules的配置方法
- 在Create React App中使用CSS Modules的方法示例
- 在create-react-app中使用css modules的示例代碼
- 詳解使用create-react-app添加css modules、sasss和antd
- react使用css module無法重寫bootstrap樣式問題及解決
相關文章
react國際化化插件react-i18n-auto使用詳解
這篇文章主要介紹了react國際化化插件react-i18n-auto使用詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-03-03
React超詳細分析useState與useReducer源碼
我正在處理的組件是表單的時間輸入。表單相對復雜,并且是動態(tài)生成的,根據(jù)嵌套在其他數(shù)據(jù)中的數(shù)據(jù)顯示不同的字段。我正在用useReducer管理表單的狀態(tài),到目前為止效果很好2022-11-11
使用webpack搭建react開發(fā)環(huán)境的方法
本篇文章主要介紹了使用webpack搭建react開發(fā)環(huán)境的方法,在這篇文章中我們開始利用我們之前所學搭建一個簡易的React開發(fā)環(huán)境,用以鞏固我們之前學習的Webpack知識。一起跟隨小編過來看看吧2018-05-05

