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

生成Debug APK时遇Unable to resolve module错误:无法解析指定模块文件

解决React Native生成Debug APK时的empty-module.js模块解析错误

方案1:清理各类缓存

  • 重置Metro缓存:
    npx react-native start --reset-cache
    
  • 删除依赖文件后重新安装:
    rm -rf node_modules
    rm package-lock.json yarn.lock
    npm install # 若使用yarn则替换为yarn install
    
  • 清理Android构建缓存:
    cd android && ./gradlew clean && cd ..
    

方案2:校验Metro配置

  • 检查项目根目录的metro.config.js,确保配置无错误路径映射,默认配置示例:
    const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
    const config = {};
    module.exports = mergeConfig(getDefaultConfig(__dirname), config);
    
  • 若有自定义resolver规则,确认未误排除metro-runtime相关模块。

方案3:对齐依赖版本

  • 避免使用全局React Native CLI,改用本地CLI执行构建:
    npx react-native run-android
    
  • 检查package.json中metro-config、metro-runtime版本,确保与项目react-native版本兼容,必要时手动指定版本后重新安装依赖。

方案4:修复文件权限(类Unix系统)

  • 若全局node_modules目录权限异常,执行以下命令修复:
    sudo chown -R $USER:$GROUP /usr/local/lib/node_modules
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 02:25:40