Skip to content

WebPack/TypeScript: jspdf_1.default is not a constructor #956

@matb

Description

@matb

I am using jsPdf in the version that is currently published via NPM in an Angular2 app written in Typescript.

We have the following code:

import jsPDF from 'jspdf'; // this imports jspdf.debug.js
var doc = new jsPDF(); // this throws an exception
doc.text('Hello world!', 10, 10)
doc.save('a4.pdf')

When executing this we are getting the following exception: jspdf_1.default is not a constructor. I can work around the issue by patching the jsPdf.debug file as described here: #582 and additionally adding this line:
jsPDF.default = jsPDF;

In addition I tried the latest files in the dist folder of the master branch. With those files, I need to add this line at the end of jspdf.debug.js:

 })(typeof self !== "undefined" && self || typeof window !== "undefined" && window || undefined);
  jsPDF.default = jsPDF; // new
  return jsPDF;

Is there any workaround without changing the files in the node_modules folder?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions