geolocator
geolocator copied to clipboard
ReferenceError: window is not defined (SSR support)
Hi,
The source you've pushed to npm invokes window even though its not required and also not in the original source code. This prevents this library from being used in server-side rendered react projects like Gatsby.js
You might want to build the source with Webpack instead of babel directly.
ERROR #95312
"window" is not available during server side rendering.
See our docs page for more info on this error : https://gatsby.dev/debug-html
WebpackError: ReferenceError: window is not defined
geolocator.js:14 Object../node_modules/geolocator/dist/geolocator.js
node_modules/geolocator/dist/geolocator.js:14:2
It seems you guys need to update /node_modules/geolocator/dist/geolocator.js with below check for window object.
if(typeof window !== 'undefined') {
// the entire file contents.
}
As far as I can see, all the reference(s) to window
are there to check that the environment has a global reference for the geolocator
API.
In node.js backends, there supposedly is no support for the API at this point (2022-01-22), so checking that this code is only executed on browser(s) with support for the API seems like a proper precaution.
If I've misunderstood the issue, please elaborate.