react-native-maps: react-native-maps crash undefined is not a function
Summary
Updated to the latest version (from 0.31.0) and now each time I try to render child (Polygon, Marker, etc) the app is crashing with “this.getNativeComponent undefined”

Reproducible sample code
import React from 'react';
import {
Platform,
} from 'react-native';
import MapView, {Polygon, PROVIDER_DEFAULT, PROVIDER_GOOGLE} from 'react-native-maps';
export default function App() {
return (
<MapView
style={{flex: 1}}
provider={Platform.OS === 'ios' ? PROVIDER_DEFAULT : PROVIDER_GOOGLE}
mapType={'hybrid'}
initialRegion={{
latitude: 42,
longitude: 30,
latitudeDelta: 1,
longitudeDelta: 1,
}}
>
<Polygon key={'polygon'} coordinates={[{
latitude: 42,
longitude: 30}]} />
</MapView>
);
}
Steps to reproduce
- update to latest version react native and react native maps
- use the snippet above
- app crash with the error “this.getNativeComponent undefined”
Expected result
the app renders a map
Actual result
app crashing
React Native Maps Version
1.3.2
What platforms are you seeing the problem on?
Android, iOS (Apple Maps), iOS (Google Maps)
React Native Version
0.70.1
What version of Expo are you using?
Not using Expo
Device(s)
iPhone 13 (iOS 16) | Android Pixel 5 (API 31)
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 4
- Comments: 20
I had the same issue and thanks to @matan-atiya’s advise I found out that in my case I have to remove ‘@babel/plugin-proposal-class-properties’ plugin from babel.config.js (moving it to .babelrc didn’t work for me).
However, “mobx” package requires that plugin so I have to keep it. Eventually I had to use “overrides” to bypass the plugin for the files in “node_modules” to make it work.
Hope this helps somebody.
Still valid w/ :
for people landing here: in my example I had to avoid transpiling react native maps with the transform-private-methods (you most likely will have a different plugin here)
There are some problems in your answer, the following is my modification:
After the above changes, my project works fine
@jaalvarez2818 In my case, I accessed node_modules -> react-native-maps -> lib -> MapMarker.js (commented “getNativeComponent”) and MapPolyline.js (commented “getNativeComponent”).
Hi, it seems this bug isn’t so much related to the react-native-maps package, I found the problem and fix it.
It seems that the Babel plugins I added to my project in the old react native version in the bable.confing.js file cause the problem. Although adding them to that file worked fine in the old version, in the new one it seems to cause the metro bundler to link only parts of the packages to the application, and that caused the map view to be loaded in the app, and for the other components that are imported from the package like Marker, Polygon, etc to be undefined - what’s caused the app to crash when using them.
Moving the Babel plugins to .babelrc file fix my issue - hope it will help others who encountered the same problem.
This solution 100% worked for me. Thank you you made my day
Hi, I upgraded to the last React Native version currently available - 0.72.4, and the last React Native Maps and mobx that are currently available (react-native-maps - 1.7.1 and mobx - 6.10.2, mobx-react-lite -4.0.4). the plugin that caused the bug in the first place is not needed in those versions anymore (at least in my project), so maybe try to update your project and remove the plugin if it is not necessary in your project after the update, hope that will help.