5

I have borrowed the code from here and I am trying to make it work as a proof of concept in my React application.One of the issues I encounter is with line:

var pdf = new jspdf('p', 'pt', 'letter');

In such case I get the following error: TypeError: WEBPACK_IMPORTED_MODULE_2_jspdf.jspdf is not a constructor

If I remove 'new' var pdf = jspdf('p', 'pt', 'letter');

I am getting the error: TypeError: Object(...) is not a function

What am I doing wrong. It seems like it is working in all examples, but no in my editor :)

py_script
  • 808
  • 2
  • 16
  • 38

1 Answers1

1

It's a typo

const jsPDF = require('jspdf')
var pdf = new jsPDF('p', 'pt', 'letter')
AthMav
  • 196
  • 1
  • 8
  • Hmm, not sure what I am missing here. This is the only way my app compiles, given I have a typo: #### import {jsPDF} from 'jspdf'; .... var pdf = jsPDF('p', 'pt', 'letter'); #### but still it breaks like above(TypeError: Object(...) is not a function ) – py_script Oct 02 '17 at 13:16
  • No it didnt. I am getting an error saying: TypeError: Object(...) is not a function. So I am in a place, where I cannot use it both as constructor and function? – py_script Oct 02 '17 at 13:27
  • Not sure why, I see it is used as constructor here: https://github.com/MrRio/jsPDF/blob/master/examples/html2pdf/lists.html – py_script Oct 02 '17 at 13:28
  • I dont know.... try importing it from the html – AthMav Oct 02 '17 at 13:29
  • YESSS!! That worked. It was kinda obscure. Many thanks for the hint @AthMav :) – py_script Oct 02 '17 at 13:38
  • which did it? the one from github? import * as jsPDF from jspdf? – AthMav Oct 02 '17 at 13:42
  • 1
    the const jsPDF = require('jspdf') one. the import * as jsPDF from jspdf was failing to compile – py_script Oct 02 '17 at 13:43