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

在EAS服务器构建APK时react-native-maps报错:导入Web不支持的原生模块

解决EAS构建APK时react-native-maps的web模块导入报错问题

报错核心是expo-router在打包server manifest时误触发了web环境的模块检测,即便你目标是Android平台。以下是几个可行的解决方法:

  • 明确指定构建平台
    执行EAS构建时加上--platform android参数,确保构建流程完全针对原生平台,避免触发web打包逻辑:

    eas build --platform android
    
  • 条件导入react-native-maps组件
    在代码里通过Platform判断环境,只在原生端导入相关组件,避免web端打包时加载原生模块:

    import { Platform } from 'react-native';
    
    let MapView, Marker;
    if (Platform.OS !== 'web') {
      ({ MapView, Marker } = require('react-native-maps'));
    }
    
    // 使用时先判断组件是否存在
    export default function MapScreen() {
      if (!MapView) return null;
      return <MapView><Marker /></MapView>;
    }
    
  • 调整Babel配置忽略web端的react-native-maps
    在babel.config.js中添加环境判断,仅在web生产环境将react-native-maps映射为空模块:

    module.exports = function(api) {
      api.cache(true);
      return {
        presets: ['babel-preset-expo'],
        env: {
          production: {
            plugins: [
              process.env.EXPO_PLATFORM === 'web' && [
                'module-resolver',
                {
                  alias: {
                    'react-native-maps': './empty-module.js',
                  },
                },
              ],
            ].filter(Boolean),
          },
        },
      };
    };
    

    然后在项目根目录创建empty-module.js:

    export default {};
    
  • 更新依赖版本并清理缓存
    确保expo和react-native-maps版本兼容,执行更新命令:

    npm install expo@latest react-native-maps@latest
    

    之后清理EAS构建缓存再重新构建:

    eas build --clear-cache --platform android
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 19:46:01