Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Error - window is not defined for React/Nextjs #514

Open
rwsabhishek opened this issue Oct 31, 2022 · 2 comments
Open

Error - window is not defined for React/Nextjs #514

rwsabhishek opened this issue Oct 31, 2022 · 2 comments

Comments

@rwsabhishek
Copy link

rwsabhishek commented Oct 31, 2022

I am facing the below error in react/next js - window is not defined

MY SOLUTION - So to resolve this for now, I have to edit the node module postscribe.js file and add following conditions in line 1335.
image
image

Edited Code on line 1335 - var work={}; if (typeof window !== "undefined") work = window.document.createElement('div');

It will be helpful if you add this condition at your module js file. So i will use the latest version

@thehungrycoder
Copy link

Found same issue just now. @rwsabhishek thanks for the hint. Hopefully it'll be part of core package.

@constmoon
Copy link

constmoon commented Jul 31, 2023

Try dynamic import when importing components that using postscribe.

import dynamic from 'next/dynamic'

const ExternalScriptComponent = dynamic(() => import('@/components/...'), {
  ssr: false,
})

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

No branches or pull requests

3 participants