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

Expo环境下react-native-maps导入native-only模块报错求助

React Native Expo环境中react-native-maps导入错误求助

问题详情

  • 作为React Native新手,在Expo环境中使用命令 npm expo install react-native-maps 安装了react-native-maps@1.18.0,安装时收到警告:Warning: react-native-maps does not support the New Architecture.
  • 使用组件时触发错误:InternalError Metro has encountered an error: Importing native-only module
  • 曾尝试根据react-native-maps文档,在node_modules/react-native中添加以下配置以兼容新架构,但报错未消除:
project: {
    android: {
      unstable_reactLegacyComponentNames: [
        'AIRMap',
        'AIRMapCallout',
        'AIRMapCalloutSubview',
        'AIRMapCircle',
        'AIRMapHeatmap',
        'AIRMapLocalTile',
        'AIRMapMarker',
        'AIRMapOverlay',
        'AIRMapPolygon',
        'AIRMapPolyline',
        'AIRMapUrlTile',
        'AIRMapWMSTile',
      ],
    },
    ios: {
      unstable_reactLegacyComponentNames: [
        'AIRMap',
        'AIRMapCallout',
        'AIRMapCalloutSubview',
        'AIRMapCircle',
        'AIRMapHeatmap',
        'AIRMapLocalTile',
        'AIRMapMarker',
        'AIRMapOverlay',
        'AIRMapPolygon',
        'AIRMapPolyline',
        'AIRMapUrlTile',
        'AIRMapWMSTile',
      ],
    },
  },
};

当前依赖版本

{
  "expo": "^52.0.25",
  "expo-constants": "^17.0.4",
  "expo-linking": "^7.0.4",
  "expo-router": "^4.0.16",
  "expo-status-bar": "^2.0.1",
  "nativewind": "^4.1.23",
  "react": "18.3.1",
  "react-native": "^0.76.6",
  "react-native-safe-area-context": "4.12.0",
  "react-native-screens": "^4.4.0",
  "react-native-web": "~0.19.13",
  "react-native-maps": "1.18.0"
}

可行解决方案

  • 禁用新架构:Expo 52默认启用新架构,但react-native-maps暂不支持。在app.json或app.config.js中添加配置关闭新架构:

    {
      "expo": {
        "newArchEnabled": false
      }
    }
    

    执行npx expo start --clear清除缓存后重启项目。

  • 避免修改node_modules:直接修改node_modules/react-native内的配置无法持久化,且Expo环境下不生效,所有配置应在项目自有文件中进行。

  • 检查导入方式:确保使用标准导入方式,不要直接导入Native-only模块:

    import MapView from 'react-native-maps';
    
  • 重装依赖并清缓存:删除node_modules和package-lock.json,运行npm install重新安装依赖,再执行npx expo start --clear启动项目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 02:50:04