Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: window is not defined (SSR support) #70

Open
Shashank-Yara opened this issue Apr 16, 2020 · 1 comment
Open

ReferenceError: window is not defined (SSR support) #70

Shashank-Yara opened this issue Apr 16, 2020 · 1 comment

Comments

@Shashank-Yara
Copy link

Shashank-Yara commented Apr 16, 2020

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.
}
@Shashank-Yara Shashank-Yara changed the title ReferenceError: window is not defined ReferenceError: window is not defined (SSR support) Apr 16, 2020
@DiscoNova
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants