MacBook M1/M2 芯片使用react-native老版本兼容问题解决

1、yoga报错

react-native/ReactCommon/yoga/yoga/Yoga.cpp:2285:9: error: use of bitwise '|' with boolean operands [-Werror,-Wbitwise-instead-of-logical]
node->getLayout().hadOverflow() |
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
||

Yoga.cpp:2285:9| 修改成 ||

2、openssl 版本与 node 的兼容问题导致报错容易在 m1/m2 芯片发生

Failed to construct transformer: Error: error:0308010C:digital envelope routines::unsupported
at new Hash (node:internal/crypto/hash:79:19)
at Object.createHash (node:crypto:139:10)
...
{
opensslErrorStack: [
'error:03000086:digital envelope routines::initialization error',
'error:0308010C:digital envelope routines::unsupported'
],
library: 'digital envelope routines',
reason: 'unsupported',
code: 'ERR_OSSL_EVP_UNSUPPORTED'
}

这是由于openssl版本与node版本在M1/M2芯片兼容问题导致的
解决方法可以参考如下:

1 在 .zshrc 或者 .bashrc 中加入

export NODE_OPTIONS=--openssl-legacy-provider
# 然后 source ~/.zshrc 或者 source ~/.bashrc

2 在 ios 目录下新建 .xcode.env.local 增加

export NODE_OPTIONS=--openssl-legacy-provider

3 如果没效果,在 xcode 打开项目,在 Targets -> Build Phases -> Start Packager 加入如下内容

export RCT_METRO_PORT="${RCT_METRO_PORT:=8081}"
export NODE_OPTIONS=--openssl-legacy-provider #需要加入的配置
echo "export RCT_METRO_PORT=${RCT_METRO_PORT}" > "${SRCROOT}/../node_modules/react-native/scripts/.packager.env"

react native 清除缓存 – 可能有效

rm -rf ~/Library/Developer/Xcode/DerivedData/*
watchman watch-del-all
rm -rf $TMPDIR/react-_
rm -rf $TMPDIR/metro-_
rm -rf ios/build
npm cache clean --force
npx pod-install

重新安装 podfile 依赖

pod cache clean --all
pod deintegrate
pod install

最后注意终端和配置是否生效

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值