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.

How to use jsPDF in node? Gets _jspdf2.default is not a constructor error

See original GitHub issue

I tried to import jspdf like this in my node app :

import jsPDF from 'jspdf';

Then tried to use the example code :

var doc = new jsPDF();
doc.text(20, 20, 'Hello world.');
doc.save('Test.pdf');

Then I get an error saying _jspdf2.default is not a constructor error. What is the right way to do this?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:4
  • Comments:13

github_iconTop GitHub Comments

23reactions
oscarocegueracommented, Jun 30, 2016

try in index.html => https://cdnjs.com/libraries/jspdf

14reactions
devvmhcommented, Aug 22, 2016

@THPubs I think you’ll need to do one of these:

const jsPDF = require('jspdf')

or

import * as jsPDF  from 'jspdf'

This is because es6 import syntax is subtly different than node’s import syntax. Probably you’re best off using node require, unless this lib is updated to better accommodate es6.

I’m not 100% sure how it all works. there’s more discussion at, for example, https://github.com/Microsoft/TypeScript/issues/5565

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use jsPDF in node? Gets _jspdf2.default is not a ...
I tried to import jspdf like this in my node app : import jsPDF from 'jspdf'; ... Gets _jspdf2.default is not a constructor...
Read more >
How to use jsPDF in Angular 7? Gets ...
The error is caused by the import statement. import { jsPDF } from 'jspdf';. Change to: import jsPDF from 'jspdf';.
Read more >
Using jsPDF in custom widget - Esri Community
I am trying to use a third party library (jsPDF) in my custom widget and I am getting the error. jsPDF is not...
Read more >
jspdf - npm
Start using jspdf in your project by running `npm i jspdf`. There are 1012 other projects in the npm registry using jspdf.
Read more >
jspdf - UNPKG
The CDN for jspdf. ... jspdf/dist/jspdf.umd.min.js.map ... 'pdfobjectnewwindow' -> (window | null) throws error if global isn't a window object(node)<br/>\n ...
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