Downloading a pdf with jsPdf library, what's wrong with my code?

    <script src=""></script>
    <script type='text/javascript'>
        import { jsPDF } from "jspdf";

        // Default export is a4 paper, portrait, using millimeters for units
        function test(){
          const doc = new jsPDF();

          doc.text("Hello world!", 10, 10);
    <a href='javascript:test()'>link</a>


From the docs:

The import statement cannot be used in embedded scripts unless such script has a type="module".

I think that might be your issue - sorry, I don’t do this kind of thing much anymore. And I would use something like webpack so I could break apart these things into separate files and use full ES6.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.