Print.js: How to add this using NUXT ?

Created on 7 Mar 2019  路  11Comments  路  Source: crabbly/Print.js

Anyone already integrate this to nuxtjs?
Locally and CDN ?

Most helpful comment

Possible solution: https://codesandbox.io/s/1q52zvkyy3

User dynamic import when page mounts.

Or try to inject print as a global :
https://nuxtjs.org/guide/plugins#inject-in-root-amp-context
https://nuxtjs.org/guide/plugins#client-side-only

All 11 comments

Hi @jaasaria, I haven't used Nuxt yet, therefore, I don't have any input with using the lib with it.
Shouldn't you be able to import it just like any other package though?

Hi @crabbly , thanks for the quick reply.
The package is working but after refreshing the page. It gives me this error.

Window is not defined

Interesting. The library does a check to see if window is available:
https://github.com/crabbly/Print.js/blob/master/src/index.js#L6

Are you sure this error is coming from print-js?

If yes, could you please setup a codesandbox, using nuxt and importing printjs to replicate the issue?
I could then jump on it and try to figure this out with you. Thank you.

https://codesandbox.io/

@crabbly check this
https://codesandbox.io/s/3y52v3ywpp?fontsize=14

Go to about page. Please let me know if something have problem with the codesandbox. Thanks

Thank you, @jaasaria

I'm not getting the error here. It is working fine for me. :/
So far tested in Chrome and Safari.
MacOS Mojave.

What are you using it on?

Did you hit the refresh?
image

Im using Windows and Chrome

Yea. It didn't happen before, but now it's happening every time. It doesn't make much sense.
Anyways, I don't know why it is happening, but I can play with it now. Thx.

Initially, it looks like a conflict when webpack is compiling everything together.

Alright, please let me know if anything i can help from my side.
Thanks for the quick support.

Possible solution: https://codesandbox.io/s/1q52zvkyy3

User dynamic import when page mounts.

Or try to inject print as a global :
https://nuxtjs.org/guide/plugins#inject-in-root-amp-context
https://nuxtjs.org/guide/plugins#client-side-only

Awesome!
Thank you, @sppera

Hey @jaasaria, could you take a look at @sppera's solution?
It fixed the issue for me. I'm not getting that error anymore.

Yes it works! Thanks @sppera and @crabbly for the time.

Was this page helpful?
0 / 5 - 0 ratings