I am trying to use jsPdf in angular universal. I get this error in universal mode:
ReferenceError: html2pdf is not defined
any fix for this?
I started receiving this error in my jest tests while refactoring (using an aurelia-typescript-webpack4 app). Kind of hacky, but i removed import * as jspdf from 'jspdf and used a const jsPDF = require('jspdf'); in the actual method that was using library. Not sure if that helps.
I am also getting html2pdf not defined. The important thing is it works well until I am not writing the unit test using mocha n enzyme. It creates issue due to writing shallow in unit test. I don't understand what is the link of unit test with html2pdf, even I am only using jspdf not even installed html2pdf. please suggest some solution !!
Any chance the library will ever work with node?
ReferenceError: html2pdf is not defined
at /Users/tapani/projects/x/node_modules/jspdf/dist/jspdf.min.js:202:16291
at /Users/tapani/projects/x/node_modules/jspdf/dist/jspdf.min.js:1:62
at Object.<anonymous> (/Users/tapani/projects/x/node_modules/jspdf/dist/jspdf.min.js:1:66)
at Module._compile (internal/modules/cjs/loader.js:778:30)
I am also getting ReferenceError: html2pdf is not defined when writing unit tests. Is there any fix for this yet please?
Thanks
Did you use the dist/jspdf.node.min/debug.js files? They should work on node. If not, this is a bug and should be fixed.
Did you use the
dist/jspdf.node.min/debug.jsfiles? They should work on node. If not, this is a bug and should be fixed.
Hi @HackbrettXXX , thanks for your reply. I have tried using /dist/jspdf.node.debug.js but unfortunately am still receiving the same ReferenceError: html2pdf is not defined error.
Thanks
I tried to run jsPDF on node myself and it - kind of - works. I first got an error that window is not defined. If I set window to something, e.g.
global.window = {} // or use a JS DOM implementation
it works.
The html2pdf is not defined error only occurs when using the non-node version. So I'm pretty sure Angular still resolves jsPDF to the non-node file.
Nevertheless, I think unconditionally accessing window is also bad, so I'm gonna mark this as bug.
I tried to run jsPDF on node myself and it - kind of - works. I first got an error that
windowis not defined. If I set window to something, e.g.global.window = {} // or use a JS DOM implementationit works.
The
html2pdf is not definederror only occurs when using the non-node version. So I'm pretty sure Angular still resolves jsPDF to the non-node file.Nevertheless, I think unconditionally accessing window is also bad, so I'm gonna mark this as bug.
Using Nuxtjs, I'm experiencing window is not defined error too :

// Right below your imports
if (process.client) {
JsPDF = require('jspdf')
html2canvas = require('html2canvas')
}
I'm using it this way with node. Probably all lines are not needed anymore.
global.window = {document: {createElementNS: () => {return {};} }};
global.navigator = {};
global.btoa = require('btoa');
global.atob = require('atob');
global.html2pdf = {};
const jsPDF = require('jspdf/dist/jspdf.node.debug');
const { applyPlugin } = require('./node_modules/jspdf-autotable/dist/jspdf.plugin.autotable');
applyPlugin(jsPDF);
Why is this closed?
It is not closed. The other issue is closed ;)
I am getting "ReferenceError: html2pdf is not defined" too. I used the html2pdf.bundle.js
If I am using jsPDF alone I get "ReferenceError: jspdf is not defined" obviously. - I tried the versions with es and umd. No luck.
Sad, because this tool looks promising.
@ReverendLove could you share a minimal repro?
Never mind. My fault.
Wordpress didn't like including it via
Most helpful comment
It is not closed. The other issue is closed ;)