Print.js icon indicating copy to clipboard operation
Print.js copied to clipboard

Error occurs while Next js building: ReferenceError: window is not defined.

Open zulzhan opened this issue 2 years ago • 5 comments

Hi! Can we use print js in SSR projects?

zulzhan avatar May 30 '22 10:05 zulzhan

yeap, I also encountered such problems.

napster99 avatar Jun 08 '22 06:06 napster99

Hi! Can we use print js in SSR projects?

you can avoid this by delaying the loading of print.js. load it during the runtime instead of build time

hassam7 avatar Jun 17 '22 11:06 hassam7

If you intend to use Print.js on the client side then you could import it dynamically when the user action is executed like this:

const printJS = (await import("print-js")).default

Take a look at Next.js docs for dynamic imports.

dbruvers avatar Dec 08 '22 10:12 dbruvers

Does anyone solve this? Dynamic imports didn't work for me.

tchesa avatar Apr 18 '23 19:04 tchesa

The problem is related to the loadIframeImage method trying to load images created by next/image. I'm using Next13.

tchesa avatar Apr 19 '23 01:04 tchesa