react-native-geocoder icon indicating copy to clipboard operation
react-native-geocoder copied to clipboard

Error: Undefined is not an object

Open LukeTim opened this issue 9 years ago • 12 comments
trafficstars

I am hitting an error inside the geocodeAddress function in geocoder.js.

I have performed all the necessary steps to add the library to the linker. I have these lines at the top of my index.ios.js file to test:

import Geocoder from 'react-native-geocoder';

console.log(Geocoder.geocodeAddress("London")['formattedAddress']);

I am seeing this error as soon as I load up the app in the simulator:

undefined is not an object (evaulating RNGeocoder.geocodeAddress)

The issue is on line 29 in geocoder.js:

return RNGeocoder.geocodeAddress(address).catch(err => {

I am guessing that RNGeocoder is for some reason undefined. Is there something I am missing? I have installed the npm module, added the libRNGeocoder.a library to the XCode linker...

I tried adding debugging code into geocoder.js but that seemed to just produce a different error; as though the Geocoder module was no longer able to be loaded.

LukeTim avatar Jul 09 '16 10:07 LukeTim

I ran into this as well. As a sanity check, I outputted the RNGeocoder object just before I made the function call, to verify that the object is properly being imported and exists from the perspective of the calling script. I'm on RN 22.2 e.g.

my code (debugLog is a wrapper for console.log):

        debugLog('Geocoder object',Geocoder);
        Geocoder.geocodeAddress(query).then((data) => {
            ... stuff ...
        }).catch((e) => {
          debugLog('Geocoder error',e);
        })

the console logging output:

Geocoder error: Cannot read property 'geocodeAddress' of undefined(…)

Geocoder object: Object {}
  geocodeAddress: geocodeAddress(address,callback)
  reverseGeocodeLocation: reverseGeocodeLocation(location,callback)

What I did to fix was update my copy of the RNGeocoder library, upgrading to the latest. Then (since we previously had 0.2 installed), in xCode, I re-ran the iOS setup steps to add/link the latest RNGeocoder.xcodeproj and libRNGeocoder.a files. I also had to delete the old one (I think it was named something like RNGeocoderSample.) When I did a new build, it worked and the error was gone.

juellez avatar Jul 14 '16 05:07 juellez

as @juellez said this error means the JS and obj-c files are out of sync. Usually cleaning the build and recompiling the project fix this.

You can also uninstall and reinstall the lib. using rnpm is quite easy and super fast to do

devfd avatar Jul 15 '16 05:07 devfd

I'm running into the same issue as well.

Went through the process of removing the package from node_modules directory, then reinstalled, and added into the xcode project... Same issue.

Any next steps you can think of?

bryantAXS avatar Aug 09 '16 01:08 bryantAXS

clean and rebuild didn't help, running react-native link fixed it

rknell avatar Dec 11 '16 11:12 rknell

I've tried it with both manually (as on README) and react-native link (former rnpm link) command. Worths mention that I'm trying to use it for the first time in my project and I'm getting the same issue, so I guess it's not an update issue.

I've noticed something weird, though: When navigating through the project tree inside xCode, the file libRNGeocoder.a (located at Libraries/RNGeocoder.xcodeproj/Products) appears in red, and if I try to locate that file (right clicking on it -> Show in Finder), it gets nowhere, as if the file doesn't exist.

Any ideas? Thanks! =)

almirfilho avatar Dec 19 '16 20:12 almirfilho

It looks like RNGeocoder is not being included in NativeModules for some reason. The following line returns undefined:

const { RNGeocoder } = NativeModules;
console.log(RNGeocoder); // => undefined

https://github.com/devfd/react-native-geocoder/blob/master/js/geocoder.js#L4

almirfilho avatar Dec 19 '16 20:12 almirfilho

I'm facing the same issue, does anybody can solve it?

@rknell react-native link fixed it 👍 but I have to run and build it again

kiroskirin avatar Mar 07 '17 18:03 kiroskirin

Facing the same issue, who could help here Geocoder.geocodeAddress(city).then(response => { console.log('response', response); });

waelalameen avatar Jul 27 '17 22:07 waelalameen

still broken

NCal avatar Feb 01 '18 01:02 NCal

still....

Manoj002 avatar Jun 02 '18 06:06 Manoj002

yep still

ameshkin avatar Oct 05 '18 04:10 ameshkin

still broken...

axelmedeiros avatar Apr 19 '19 18:04 axelmedeiros