[@theme-ui/match-media] Breaks gatsby builds due to undefined window
See original GitHub issueUsing @theme-ui/match-media
’s useResponsiveValue
hook in Gatsby causes the build to fail, due to its use of window.matchMedia
.
I’d normally add a typeof window === 'undefined'
check, but am not allowed to conditionally call a hook. Is there an alternative userland solution for this that I’m not thinking of?
I could add the check to the hook - is returning breakpoints[0]
a sensible default?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (5 by maintainers)
Top Results From Across the Web
'window is not defined' error from build files #25298 - GitHub
During server-side rendering, the window is undefined and is probably why you're running across this error on build. Issue #309 references this ...
Read more >Gatsby build fails because window is undefined in a React hook
According to Gatsby docs window is not available during the build process. I've tried to if (typeof window !== 'undefined') condition to the ......
Read more >Gatsby - the window is not defined error, what and how to fix it?
gatsby build : It is the environment to build the application to produce deployable artifacts. You can even run the app locally from...
Read more >Troubleshooting Common Errors - Gatsby
Error: ReferenceError: window is not defined when running gatsby build; Build problems from Field 'browser' doesn't contain a valid alias configuration ...
Read more >Window is not defined in gatsby build : r/gatsbyjs - Reddit
EDIT: Problem resolved. It was occurring due to an npm package named "react-video-modal" as I have to use some different version. This is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@dburles The docs say:
I could not find a way to set the test environment for that test only.
Moved the test to its own file
ssr.js
and set the environment but@testing-library/react
’s render function relies ondocument
. None of the options it accepts helped. Tried to test the functions themselves outside of a rendered component, but the Rules of Hooks didn’t like that.Surely someone else has needed to simulate the absence of
window
so I’ll keep looking for a solution.@joestrouth1 PR Looks good. Try set the test environment to
node
for that test https://jestjs.io/docs/en/configuration.html#testenvironment-string