ReferenceError: window is not defined on NextJS Build
See original GitHub issueI have come across an issue when compiling NextJS into a published build. When you compile using next build
, it comes up with an issue ReferenceError: window is not defined.
I have worked out a fix for this which would be useful for those using the Next JS Framework. Is there a way to add this to your code?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:16
- Comments:5
Top Results From Across the Web
How to solve Next.js window is not defined
ReferenceError : window is not defined is a pretty common error you may run into when using Next.js for the first time but...
Read more >Window is not defined in Next.js React app - Stack Overflow
Next.js is universal, which means it executes code first server-side, then client-side. The window object is only present client-side, so ...
Read more >Fix for Next.js ReferenceError window is not defined
The window object is the reference to an open window in a browser. Therefore, the window object is only available on the client-side....
Read more >How to Fix "window is not defined" in Next.js - Upmostly
This issue has to do with Server-Side Rendering in Next.js. Next.js will by default try to use SSR for your site. This means...
Read more >How to fix window is not defined error in Next.js
As you can see the error occurs in the terminal itself. That means it is a compilation error. Next.js is compiled/built on Node.js...
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 Free
Top 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
Our builds stopped working on Gatsby as well. This looks like its due to the new version. We were able to fix by fixing the version to
1.2.6
:In my Next app, I used dynamic import to get around this issue.