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

Windows11下React Native + Hermes无法生成TypeScript SourceMap

React Native StagingDebug SourceMap 生成失败(目标目录不存在)解决方案
  • 确认Android Product Flavors配置
    如果你的android/app/build.gradle里没配置staging flavor,bundleInStaging参数不会生效。需要在android{}代码块中添加:

    android {
      // 保留原有其他配置
      flavorDimensions "environment"
      productFlavors {
        staging {
          dimension "environment"
          applicationIdSuffix ".staging"
        }
      }
    }
    
  • 明确指定SourceMap输出路径
    在project.ext.react配置中添加路径指定,强制文件生成到目标目录:

    project.ext.react = [
        enableHermes: true,
        bundleInStaging: true,
        bundleInRelease: true,
        hermesFlagsRelease: ["-O", "-output-source-map"],
        hermesFlagsDebug: ["-O", "-output-source-map"],
        // 新增SourceMap路径配置
        sourcemapOutput: "../android/app/build/sourcemap/index.staging.debug.map",
        sourcemapSourcesRoot: "../../",
        // 变体专属配置(可选,确保stagingDebug生效)
        stagingDebug: [
            sourcemapOutput: "../android/app/build/sourcemap/index.staging.debug.map",
            bundleInStaging: true
        ]
    ]
    
  • 清理所有缓存并重建
    Windows下执行以下命令彻底清理缓存,避免旧配置干扰:

    # 清理Yarn缓存
    yarn cache clean
    
    # 清理Android构建缓存
    cd android && ./gradlew clean
    
    # 清理Metro缓存
    npx react-native start --reset-cache
    

    清理完成后重新执行你的构建命令:

    yarn create-env --staging && react-native run-android --variant=stagingDebug --appIdSuffix=staging
    
  • 检查Hermes在stagingDebug中的启用状态
    确保stagingDebug变体也启用了Hermes,在buildTypes{}代码块中补充:

    buildTypes {
      debug {
        // 保留原有配置
        if (enableHermes) {
          hermesFlags = project.ext.react.hermesFlagsDebug
        }
      }
      stagingDebug {
        initWith debug
        // 强制启用Hermes
        if (enableHermes) {
          hermesFlags = project.ext.react.hermesFlagsDebug
        }
      }
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 20:55:18