ErrorPro / react-google-autocomplete

React components for google places API.
MIT License
473 stars 114 forks source link

Google is not defined #173

Closed Veri5ied closed 1 year ago

Veri5ied commented 2 years ago

While using the package, it works well on local machine but when deployed online, it returns google is not defined and app refuses to load. I am using the useGoogle from your library

ErrorPro commented 2 years ago

Would it be possible to send some stack traces?

supagu commented 1 year ago

usePlacesAutocompleteService.js?f5a0:108 Uncaught ReferenceError: google is not defined at buildService2 (usePlacesAutocompleteService.js?f5a0:108:7) at eval (usePlacesAutocompleteService.js?f5a0:121:7) at invokePassiveEffectCreate (react-dom.development.js?61bb:23487:1) at HTMLUnknownElement.callCallback (react-dom.development.js?61bb:3945:1) at Object.invokeGuardedCallbackDev (react-dom.development.js?61bb:3994:1) at invokeGuardedCallback (react-dom.development.js?61bb:4056:1) at flushPassiveEffectsImpl (react-dom.development.js?61bb:23574:1) at unstable_runWithPriority (scheduler.development.js?3069:468:1) at runWithPriority$1 (react-dom.development.js?61bb:11276:1) at flushPassiveEffects (react-dom.development.js?61bb:23447:1)

seems it might have been related to me having a blank apiKey, which gets loaded via a fetch. I split the component so that the hook only runs when I have a apiKey and now the problem appears to be solved.

MohammadKurjieh commented 1 year ago

Indeed @supagu setting a blank key accidentally causes this error. I haven't tested it with a dynamic key. @ErrorPro it might be good to add a key check and throw an error. This can help catch silly mistakes.