I have a compilation error in svelte with jspdf

good morning, I have doubts about how to import and correctly configure the jspdf library in svelte when doing an npm run dev, it throws me errors, I don't know very well what type of configuration is done in rollup.conf, I leave the error

<script>
import { jsPDF } from "jspdf";

const doc = new jsPDF();

    function handleClick () {
        doc.text("Hello world!", 10, 10);
        doc.save("a4.pdf");
    }


</script>



<button on:click={handleClick}>pdf descargar</button>

i have this error in terminal

error:

...and 4 other files
[!] Error: Unexpected token
node_modules/jspdf/dist/jspdf.min.js (5

 at ModuleLoader.fetchModule (/home/matias93/feature-monitoreo/plataforma-web/node_modules/rollup/dist/shared/rollup.js:18459:9)
    at async Promise.all (index 3)
    at ModuleLoader.fetchStaticDependencies (/home/matias93/feature-monitoreo/plataforma-web/node_modules/rollup/dist/shared/rollup.js:18485:34)
    at async Promise.all (index 0)
    at ModuleLoader.fetchModule (/home/matias93/feature-monitoreo/plataforma-web/node_modules/rollup/dist/shared/rollup.js:18461:9)


[2021-06-04 16:22:29] waiting for changes...

Upvotes: 0

Views: 742

Answers (1)

JHeth
JHeth

Reputation: 8386

Set inlineDynamicImports: true in your rollup.config.js like so:

export default {
  input: 'src/main.js',
  output: {
    sourcemap: true,
    format: 'iife',
    inlineDynamicImports: true,
    name: 'app',
    file: 'public/build/bundle.js'
  },
...
}

Originally answered on Reddit a while back: https://www.reddit.com/r/sveltejs/comments/jzs9z6/pdf_generation_in_svelte_using_jspdf/gde8q8b?utm_source=share&utm_medium=web2x&context=3

Upvotes: 2

Related Questions