question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ReferenceError: window is not defined on NextJS Build

See original GitHub issue

I 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:open
  • Created 2 years ago
  • Reactions:16
  • Comments:5

github_iconTop GitHub Comments

16reactions
jsfourcommented, Jun 23, 2021

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:

-    "react-modal-video": "^1.2.6",
+    "react-modal-video": "1.2.6",
13reactions
iyonagacommented, Sep 29, 2021

In my Next app, I used dynamic import to get around this issue.

import dynamic from 'next/dynamic';
const ModalVideo = dynamic(() => import('react-modal-video'), { ssr: false });
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found