react-native-maps: Marker Error: TypeError: this.getNativeComponent is not a function (it is undefined)
Summary
After installing react-native-maps, I cannot implement markers. The MapView works, but the marker does not.
Error:
ERROR Warning: TypeError: this.getNativeComponent is not a function (it is undefined)
Here is my babel.config.js file:
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
env: {
production: {
plugins: ['react-native-paper/babel'],
},
},
plugins: [
[
'module-resolver',
{
root: ['./src'],
alias: {
'@': './src',
},
},
],
['@babel/plugin-transform-class-properties', { loose: true }],
['@babel/plugin-transform-private-methods', { loose: true }],
['@babel/plugin-transform-private-property-in-object', { loose: true }],
[
'module:react-native-dotenv',
{
moduleName: 'react-native-dotenv',
path: '.env',
},
],
],
};
Running on React Native v0.75.4 React Native Maps version: 1.20.1
Reproducible sample code
<View style={{ flex: 1 }}>
<MapView
style={StyleSheet.absoluteFillObject}
initialRegion={INITIAL_REGION}
showsUserLocation
showsMyLocationButton
ref={mapRef}
onRegionChangeComplete={onRegionChange}
>
{markers.map((marker, index) => (
<MapMarker
key={index}
title={marker.name}
coordinate={marker}
onPress={() => onMarkerSelected(marker)}
>
<Callout onPress={calloutPressed}>
<View style={{ padding: 10 }}>
<Text style={{ fontSize: 24 }}>Hello</Text>
</View>
</Callout>
</MapMarker>
))}
</MapView>
</View>
Steps to reproduce
Just try to call the Marker component
Expected result
I expect to display markers on the map
Actual result
ERROR Warning: TypeError: this.getNativeComponent is not a function (it is undefined)
React Native Maps Version
1.20.1
What platforms are you seeing the problem on?
Android, iOS (Apple Maps), iOS (Google Maps)
React Native Version
0.75.4
What version of Expo are you using?
Not using Expo
Device(s)
iPhone 15 Pro Max
Additional information
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 15
I tested my code in a new project that only includes this lib and the code worked. So I realized that there is a conflict between libs in my project that causes the error (I don’t know which libs cause the conflict). For now I solved it by changing the file node_modules/react-native-maps/lib/MapMarker.js I commented line 32 like this
After changing the code works and I can render a marker.
After it works I wanted to ensure that I will not release a version when this line is not commented so I asked gpt to write me a code that checks the line and if necessary comments it. Hope this helps you too
I am facing the same issues with “react-native”: “0.78.2” and “react-native-maps”: “1.22.1”.
i am also facing same issues react-native-maps1.20.1 version ,some one please update correct answer .
This fix may help. I have react-native version 0.79.1 and react-native-maps version 1.21.0 installed. I have modified the MapMarker.tsx, MapCallout.tsx and decorateMapComponent.ts files to achieve the results. I also created the patch file just incase. I have shared all the files below.
patch changes.zip
react-native-maps+1.21.0.patch
@olipda please don’t use this lib with the latest version of react-native, for now Fabric is not supported yet (in progress)
see: https://github.com/react-native-maps/react-native-maps/issues/5206#issuecomment-2504728236 and main readme