You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native在Bitrise Apple Silicon(Node.js18)构建报ERR_OSSL_EVP_UNSUPPORTED错误

解决React Native在Bitrise Apple Silicon(Node.js 18)构建的ERR_OSSL_EVP_UNSUPPORTED错误

以下是针对你的场景(Bitrise Apple Silicon虚拟机、Node.js 18,本地Node.js 16正常)的可行解决方案,按优先级尝试:

1. 临时启用OpenSSL旧兼容模式(最快验证)

在Bitrise的构建命令前添加NODE_OPTIONS="--openssl-legacy-provider"环境变量:

  • 如果用npm脚本构建,修改package.json中的脚本:
    "scripts": {
      "build:ios": "NODE_OPTIONS='--openssl-legacy-provider' react-native run-ios --configuration Release",
      "build:android": "NODE_OPTIONS='--openssl-legacy-provider' react-native run-android --variant=release"
    }
    
  • 如果直接在Bitrise的「Script」步骤执行命令,改成:
    NODE_OPTIONS="--openssl-legacy-provider" yarn install && yarn build:ios
    

2. 替换Metro的哈希算法(彻底解决兼容问题)

修改项目根目录的metro.config.js,自定义缓存哈希算法,绕过Metro默认的不兼容实现:

const crypto = require('crypto');
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');

const customConfig = {
  transformer: {
    getCacheKey: async (fileData, filename, options) => {
      // 使用Node.js 18支持的SHA-256算法生成缓存键
      const hash = crypto.createHash('sha256');
      hash.update(fileData);
      hash.update(filename);
      hash.update(JSON.stringify(options));
      return hash.digest('hex');
    },
  },
};

module.exports = mergeConfig(getDefaultConfig(__dirname), customConfig);

3. 升级Metro依赖到兼容版本

如果你的项目Metro版本较低(低于0.76.x),直接升级相关依赖到最新稳定版,这些版本已修复Node.js 18的OpenSSL兼容问题:

yarn add metro@latest metro-cache@latest metro-transform-worker@latest @react-native/metro-config@latest --dev

或用npm:

npm install metro@latest metro-cache@latest metro-transform-worker@latest @react-native/metro-config@latest --save-dev

4. Bitrise环境专属调试与修复

  • 确认Bitrise的Node.js版本:在构建步骤前添加脚本,执行node -v和echo $NODE_OPTIONS,确保环境变量未被覆盖。
  • 清理依赖缓存:Bitrise的缓存可能保留旧版本依赖,添加步骤执行:
    yarn cache clean && rm -rf node_modules && rm yarn.lock && yarn install
    
    (npm则是npm cache clean --force && rm -rf node_modules && rm package-lock.json && npm install)

内容的提问来源于stack exchange,提问作者user21992702

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 08:14:54