react-native-maps: this.getNativeComponent is not a function (it is undefined)
Summary
I am trying to use <Polyline /> component, however the app crashes with the this.getNativeComponent is not a function (it is undefined) Currently crashing on android, I haven’t tried on iOS.
Reproducible sample code
import MapView, { PROVIDER_GOOGLE, Polyline } from 'react-native-maps';
const Map = () => {
return (
<MapView
provider={PROVIDER_GOOGLE}
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
style={{ height: '100%', width: '100%' }}
>
<Polyline
coordinates={[{"latitude": 40.44375, "longitude": -79.95392}, {"latitude": 40.44355, "longitude": -79.95368}, {"latitude": 40.44327, "longitude": -79.95355}, {"latitude": 40.44329, "longitude": -79.95345}, {"latitude": 40.44317, "longitude": -79.9534}, {"latitude": 40.44313, "longitude": -79.95336}, {"latitude": 40.44305, "longitude": -79.95316}, {"latitude": 40.44301, "longitude": -79.95313}, {"latitude": 40.44298, "longitude": -79.95307}, {"latitude": 40.44259, "longitude": -79.95261}, {"latitude": 40.44255, "longitude": -79.95265}, {"latitude": 40.44244, "longitude": -79.95262}, {"latitude": 40.4424, "longitude": -79.95254}, {"latitude": 40.44238, "longitude": -79.95248}, {"latitude": 40.44239, "longitude": -79.9524}, {"latitude": 40.4424, "longitude": -79.95239}, {"latitude": 40.44231, "longitude": -79.95227}, {"latitude": 40.4421, "longitude": -79.95249}, {"latitude": 40.442, "longitude": -79.95258}]}
/>
</MapView>
)
}
export default Map
Steps to reproduce
- install the latest expo (typescript template)
- download the necessary dependencies
- copy the code above
Expected result
Map renders with polyline
Actual result
App crashes with this.getNativeComponent is not a function (it is undefined)
React Native Maps Version
1.7.1
What platforms are you seeing the problem on?
Android
React Native Version
0.72.5
What version of Expo are you using?
SDK 48
Device(s)
Samsung A32
Additional information
I am using Expo 49, the dropdown doesn’t have that option. If I remove the <Polyline /> component, the map component <MapView /> itself works no issue. I also tried to use <Marker />, the same error pops up.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 13
- Comments: 46
For anyone landing here recently: just go to
node_modules/react-native-maps/lib/MapMarker.js:32and delete:getNativeComponent;i removed some babel plugins and removed node_modules then reinstalled and restart if not working with ‘module:metro-react-native-babel-preset’ then use ‘module:@react-native/babel-preset’
I changed
module:metro-react-native-babel-preset->module:@react-native/babel-preset, and problem solved!When I use
module:metro-react-native-babel-preset, I have to install@babel/plugin-transform-private-methods. And above solutions (overrides) doesn’t work for me. So, I changed preset and don’t install that problematic plugin(@babel/plugin-transform-private-methods).This is my source code: https://github.com/S-KEEP/S-KEEP_Front/pull/17/commits/29c580d1826e0fee163ae98bb8ac5073e9d4e9ea
I have the same issue when I added a Marker. My react-native version is
0.74.6, any solution??by removing the
getNativeComponentyou can’t render markers anymore, correct?This worked for me too, but I agree its a hucky solution. Any other solution ?
Meanwhile the patch-package: react-native-maps+1.15.6.patch
This is what I’m doing for my project so that every time I reinstall dependencies with
npm ithe marker works.react-native-maps+1.20.1.patchwith the following contents:package.json:react-native-maps+1.20.1.patchshould be in the same directory aspackage.json.it worked
I was able to fix the issue thanks to the instructions from this video. You can refer to the guidance in this video: https://www.youtube.com/watch?v=AjMV8S59v-Y Wishing you success!
+1
This one still working. Thnaks man.
Hello everyone, after reading all your comment and testing some of them this solution worked, not apply the plugins on google maps package:
module.exports = function (api) { api.cache(true);
return { presets: [ ‘module:metro-react-native-babel-preset’, // Required for React Native transformations ], plugins: [ ‘react-native-reanimated/plugin’, // Required for React Native Reanimated
}; };
Try adding this in your babel.config.js
overrides: [{ test: fileName => !fileName.includes(‘node_modules/react-native-maps’), plugins: [[“@babel/plugin-transform-private-methods”, { “loose”: true }]] }],
post that delete node modules, yarn.lock, pods folder (ios), podfile.lock and then do yarn and pod It worked for me