crabbly / Print.js

A tiny javascript library to help printing from the web.
MIT License
4.28k stars 672 forks source link

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

Open zulzhan opened 2 years ago

zulzhan commented 2 years ago

Hi! Can we use print js in SSR projects?

napster99 commented 2 years ago

yeap, I also encountered such problems.

hassam7 commented 2 years ago

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

dbruvers commented 1 year ago

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.

tchesa commented 1 year ago

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

tchesa commented 1 year ago

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