Skip to content
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

throwing ReferenceError: window is not defined, when code render on server SSR #278

Closed
dvlprroshan opened this issue Mar 1, 2021 · 12 comments

Comments

@dvlprroshan
Copy link

window.Splide = complete_Splide;

image

this can be corrected using

typeof window !== "undefined"? (() => {window.Splide = complete_Splide;})(): "";
@tylerbrownhenry
Copy link

I'm having same issue

@CptCornWault
Copy link

Same here. I'm using Next.js and there is no window when doing server side rendering.

@Saunved
Copy link

Saunved commented Mar 12, 2021

The window object is not available during SSR. I am not sure how it is done in Next.js but with Nuxt, you can easily import the component as a client-side plugin to avoid window object errors

@Juliangzr
Copy link

i have tried with using dynamic component and it doesn't work either

@CptCornWault
Copy link

@Juliangzr - I had the same experience. I thought I might be doing something wrong, but it seems like I'm not the only one.

If you check out my fork, that simple change fixed it for me.

@Juliangzr
Copy link

@Juliangzr - I had the same experience. I thought I might be doing something wrong, but it seems like I'm not the only one.

If you check out my fork, that simple change fixed it for me.

Thank you! It has solved the problem!

@anujChauhan-7838
Copy link

Hey i am also facing same issue - error given below

(node:7836) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined
at Productpage.render (webpack:///./src/components/productpage/Productpage.component.js?:167:12)
at processChild (D:\honestgadgets\node_modules\react-dom\cjs\react-dom-server.node.development.js:3134:18)
at resolve (D:\honestgadgets\node_modules\react-dom\cjs\react-dom-server.node.development.js:2960:5)
at ReactDOMServerRenderer.render (D:\honestgadgets\node_modules\react-dom\cjs\react-dom-server.node.development.js:3435:22)
at ReactDOMServerRenderer.read (D:\honestgadgets\node_modules\react-dom\cjs\react-dom-server.node.development.js:3373:29)
at Object.renderToString (D:\honestgadgets\node_modules\react-dom\cjs\react-dom-server.node.development.js:3988:27)
at eval (webpack:///./server/server.js?:51:73)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
(Use node --trace-warnings ... to show where the warning was created)
(node:7836) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:7836) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

please guide what i am doing wrong.

thanks

@tylerbrownhenry
Copy link

@anujChauhan-7838 If it helps, we also ended up cloning the repo and editing the file to add if statements around the window references as well.

@ghost
Copy link

ghost commented Jul 7, 2021

I'm having same issue

@RadasLove
Copy link

RadasLove commented Aug 22, 2021

I have it same problem...

"(node:29964) UnhandledPromiseRejectionWarning: ReferenceError: window is not defined
at _callee7$ (/home/radas/Documents/webyprojekty/elupencz/elupencznext/node_modules/next-auth/dist/client/index.js:334:105)
at tryCatch (/home/radas/Documents/webyprojekty/elupencz/elupencznext/node_modules/regenerator-runtime/runtime.js:63:40)
at Generator.invoke [as _invoke] (/home/radas/Documents/webyprojekty/elupencz/elupencznext/node_modules/regenerator-runtime/runtime.js:293:22)..
........"

in my case i fix it with adding the .then / .catch method to api call

i have it just

const logIn = async () => {
const result = await signIn('credentials', {
redirect: false,
email: '*****@gmail.com',
password: 'somepassword,
}); /// need here add then // catch or promise
};

so try to find some await method without adding then or catch and fix this...

@coderDaiyan
Copy link

#116 (comment)

Follow this

@NaotoshiFujita
Copy link
Collaborator

Close the issue due to the major version update.
Feel free to create a new issue or open a new discussion.


Solved in v3.

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

No branches or pull requests

9 participants