-
Notifications
You must be signed in to change notification settings - Fork 29
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
window is not defined #36
Comments
Hi @benbowler, could you provide some context as to how you're trying to use this module? For example, are you using Next.js, Gatsby, etc.? If you could provide a code sample using Code Sandbox that would be even better. |
Just realized you typed |
I ran into a similar issue as I was trying to get CIVIC's component library to work in SSR contexts, such as Gatsby. Here's the similar error I saw running
I set up a sandbox to try to test if |
I'm also getting this error |
Currently only |
getting this error while using next.js |
Hi @Giboork, thanks for reporting the issue. Looks like this may require a PR into the suggestions dependency to fix this. I don't think In the meantime, I might be able to figure out a way to hack around this. Not sure if I'll have time this week though. If you want to try and fix it on your end for now, you can check out this SO for some ideas. https://stackoverflow.com/questions/38951721/react-js-server-side-issue-window-not-found |
I finally got a chance to look into this more. I found a workaround that works and is recommended by Zeit. https://github.com/zeit/next.js/wiki/FAQ // instead of doing this
// import Geocoder from 'react-map-gl-geocoder'
// do this
let Geocoder
if (typeof window !== 'undefined') {
Geocoder = require('react-map-gl-geocoder').default;
} At some point, I'll try and make a PR to the |
This worked for me using Gatsby JS |
For users who use next.js framework, importing mapbox-gl-geocoder dynamically will resolve the window is not defined issue. use nextjs dynamic import from next/dynamic |
@milinpaul thanks for the tip! Also, I have a PR (tristen/suggestions#42) open with the |
My PR with the |
Made a PR with |
I'm not able to load the plugin at all via pnpm.
The text was updated successfully, but these errors were encountered: