question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebPack/TypeScript: jspdf_1.default is not a constructor

See original GitHub issue

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: https://github.com/MrRio/jsPDF/issues/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?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:39 (1 by maintainers)

github_iconTop GitHub Comments

56reactions
s00500commented, Jan 18, 2018

import * as jsPDF from ‘jspdf’; works for me

6reactions
nboisteaultcommented, Dec 4, 2019

@AlbertoNava0307 Try : new jsPDF.default();

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebPack/TypeScript: jspdf_1.default is not a constructor #956
I am using jsPdf in the version that is currently published via NPM in an Angular2 app written in Typescript. We have the...
Read more >
WebPack/TypeScript: jspdf_1.default is not a constructor
WebPack /TypeScript: jspdf_1.default is not a constructor.
Read more >
Not a constructor error when importing packages for React ...
When importing using the following syntax, you are relying on there being a default export in the module: import jsPDF from 'jspdf';.
Read more >
TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >
jspdf is not a constructor
I tried to import jspdf like this in my node app : Then I get an error saying _jspdf2.default is not a constructor...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found