1

I'm trying the example from npmjs (the npmjs is installed) documentation but receiving this error in the browser.

SyntaxError: Unexpected token '{'. import call expects exactly one argument.

I have checked similar tickets here patiently however, no solution. Does anyone have an idea what could be a reason for this? Removing curly braces does not work.

import { jsPDF } from "jspdf";
const doc = new jsPDF();
doc.text("Hello world!", 10, 10);
doc.save("a4.pdf");
Stan
  • 73
  • 8
  • Check your package.json file, it must be a valid json file (especially if you edited it manually). – beerwin Mar 10 '21 at 14:16
  • That is perfectly valid Javascript. Post your HTML. You probably didn't include type="module" on the script tag. – Jared Smith Mar 10 '21 at 14:19
  • @JaredSmith thank you very much for your kind advice. I've added type="module" to the script tag. it eliminates the previous error. but give me this one: TypeError: Module specifier, 'jspdf' does not start with "/", "./", or "../". I have jspdf in node_modules also I have copied it to public folder to test. How should I write a correct path? Pathes I tried does not work. – Stan Mar 10 '21 at 16:00
  • Does this answer your question? [How will browsers handle ES6 import/export syntax](https://stackoverflow.com/questions/36523013/how-will-browsers-handle-es6-import-export-syntax) – Jared Smith Mar 10 '21 at 16:20
  • For all future viewers of my ticket here is the [template](https://stackoverflow.com/questions/16858954/how-to-properly-use-jspdf-library) which worked like a charm. Just make sure you put the correct tag id to the Source variable which will be printed to PDF. – Stan Mar 11 '21 at 12:00

1 Answers1

0

For all future viewers of my ticket here is the template which worked like a charm. Just make sure you put the correct tag id to the Source variable which will be printed to PDF.

source = $('#element_id_you_want_to_print')[0];
Stan
  • 73
  • 8