WebPack/TypeScript: jspdf_1.default is not a constructor
See original GitHub issueI 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:
- Created 7 years ago
- Reactions:2
- Comments:39 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
import * as jsPDF from ‘jspdf’; works for me
@AlbertoNava0307 Try :
new jsPDF.default();