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

React Native项目运行报错求助:TypeError与ERR_OSSL_EVP_UNSUPPORTED

针对React Native 0.64.2 + Node 18.16.0的两类错误解决方案

1. TypeError: Cannot read properties of undefined (reading 'transformFile')

  • 重置Metro缓存并清理依赖:
    npx react-native start --reset-cache
    rm -rf node_modules package-lock.json yarn.lock
    npm install # 或 yarn install
    
  • 检查metro.config.js配置,确保transformer指向正确模块,示例配置:
    module.exports = {
      transformer: {
        babelTransformerPath: require.resolve('react-native-preset'),
        getTransformOptions: async () => ({
          transform: {
            experimentalImportSupport: false,
            inlineRequires: true,
          },
        }),
      },
    };
    
  • 验证babel.config.js包含正确预设:
    module.exports = {
      presets: ['module:metro-react-native-babel-preset'],
    };
    

2. OpenSSL错误(ERR_OSSL_EVP_UNSUPPORTED)

Node 17+启用了新OpenSSL算法,与RN 0.64.x不兼容,可通过以下方式解决:

  • 临时设置环境变量(当前终端会话生效):
    • macOS/Linux:
      export NODE_OPTIONS=--openssl-legacy-provider
      
    • Windows(Cmd):
      set NODE_OPTIONS=--openssl-legacy-provider
      
    • Windows(PowerShell):
      $env:NODE_OPTIONS="--openssl-legacy-provider"
      
  • 永久集成到package.json脚本(推荐):
    修改package.json中的运行脚本,添加环境变量:
    "scripts": {
      "start": "NODE_OPTIONS=--openssl-legacy-provider react-native start",
      "android": "NODE_OPTIONS=--openssl-legacy-provider react-native run-android",
      "ios": "NODE_OPTIONS=--openssl-legacy-provider react-native run-ios"
    }
    
  • 确认Node版本切换生效:
    若用nvm切换到RN 0.64推荐的Node 14/16版本,需重启终端并运行node -v确认版本,之后重新安装依赖。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.23 12:57:08