kempsteven / vue-html2pdf

vue-html2pdf converts any vue component or element into PDF, vue-html2pdf is basically a vue wrapper only and uses html2pdf.js behind the scenes.
https://www.npmjs.com/package/vue-html2pdf
MIT License
440 stars 74 forks source link

Nuxt.js window is not defined in full static mode #68

Open mauro-alfatauristudio opened 3 years ago

mauro-alfatauristudio commented 3 years ago

Hi there,

my application is developed with Vue and Nuxt for static content. the plugin is working fine when the website is running in dev but when I generate the static pages i get this error:

ReferenceError: window is not defined at C:\Documents\app-location\app-location\node_modules\jspdf\dist\jspdf.min.js:37:30237

Any Idea how to solve it?

Thanks

mauro-alfatauristudio commented 3 years ago

This is how i imported the plugin in nuxt.config.js

 plugins: [
    { src: '~plugins/vue-html2pdf.client.js', mode: 'client' },  
  ],

This is the vue-html2pdf.client.js' :

import Vue from 'vue'
import VueHtml2pdf from 'vue-html2pdf'
Vue.use(VueHtml2pdf)
yoerriwalstra commented 3 years ago

Have you wrapped your <vue-html2pdf> component in Nuxt's <client-only> component, as explained in the Using in Nuxt.js section?

I'm planning to implement vue-html2pdf in my own Nuxt statically generated site, which is how I came across your issue. I haven't tried to deploy my site yet, but I didn't run into any issues myself when I ran npm run generate locally.

dalmia commented 2 years ago

If anyone came here looking for a solution for NuxtV3, I was able to use the base package html2pdf directly by defining a custom plugin. I have explained my answer here.

Hope it helps!