vue-html2pdf
vue-html2pdf copied to clipboard
Nuxt.js window is not defined in full static mode
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
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)
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.
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!