關(guān)于React Native報(bào)Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>錯(cuò)誤(解決方案)
最近,在運(yùn)行一個(gè)老RN項(xiàng)目的時(shí)候,使用Xcode運(yùn)行的時(shí)候報(bào)了如下的代碼錯(cuò)誤:
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> *'
這是由于升級(jí)XCode 12.5之后的問(wèn)題,在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 命令安裝即可。
到此這篇關(guān)于關(guān)于React Native報(bào)Cannot initialize a parameter of type'NSArray<id<RCTBridgeModule>>錯(cuò)誤(解決方案)的文章就介紹到這了,更多相關(guān)React Native報(bào)錯(cuò)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- React找不到模塊“./index.module.scss”或其相應(yīng)的類型聲明及解決方法
- react 報(bào)錯(cuò)Module build failed: BrowserslistError: Unknown browser query `dead`問(wèn)題的解決方法
- 在?React?Native?中使用?CSS?Modules的配置方法
- 在Create React App中使用CSS Modules的方法示例
- 在create-react-app中使用css modules的示例代碼
- 詳解使用create-react-app添加css modules、sasss和antd
- react使用css module無(wú)法重寫bootstrap樣式問(wèn)題及解決
相關(guān)文章
react國(guó)際化化插件react-i18n-auto使用詳解
這篇文章主要介紹了react國(guó)際化化插件react-i18n-auto使用詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-03-03
React超詳細(xì)分析useState與useReducer源碼
我正在處理的組件是表單的時(shí)間輸入。表單相對(duì)復(fù)雜,并且是動(dòng)態(tài)生成的,根據(jù)嵌套在其他數(shù)據(jù)中的數(shù)據(jù)顯示不同的字段。我正在用useReducer管理表單的狀態(tài),到目前為止效果很好2022-11-11
使用webpack搭建react開(kāi)發(fā)環(huán)境的方法
本篇文章主要介紹了使用webpack搭建react開(kāi)發(fā)環(huán)境的方法,在這篇文章中我們開(kāi)始利用我們之前所學(xué)搭建一個(gè)簡(jiǎn)易的React開(kāi)發(fā)環(huán)境,用以鞏固我們之前學(xué)習(xí)的Webpack知識(shí)。一起跟隨小編過(guò)來(lái)看看吧2018-05-05
如何使用Redux Toolkit簡(jiǎn)化Redux
redux-toolkit是目前redux官方推薦的編寫redux邏輯的方法,針對(duì)redux的創(chuàng)建store繁瑣、樣板代碼太多、依賴外部庫(kù)等問(wèn)題進(jìn)行了優(yōu)化,官方總結(jié)了四個(gè)特點(diǎn)是簡(jiǎn)易的/有想法的/強(qiáng)勁的/高效的,總結(jié)來(lái)看,就是更加的方便簡(jiǎn)單了2022-12-12
React實(shí)現(xiàn)一個(gè)拖拽排序組件的示例代碼
這篇文章主要給大家介紹了React實(shí)現(xiàn)一個(gè)拖拽排序組件?-?支持多行多列、支持TypeScript、支持Flip動(dòng)畫、可自定義拖拽區(qū)域,文章通過(guò)代碼示例介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11

