sooon
sooon

Reputation: 4878

svelte - import dependency package with error

I am new with Svelte and trying to import some package.

After the npm install, I import it directly into my svelte file:

import jspdf from "jspdf"

that got me the error:

Error: UMD and IIFE output formats are not supported for code-splitting builds.

then I tried to use CDN and import via HTML:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.1.1/jspdf.umd.min.js"></script>

and the svelte give me undefined error from:

var doc = new jsPDF();

I googled and some some comments and it seems like the first solution should already be working. How can I resolve this?

Upvotes: 2

Views: 907

Answers (1)

teobaj
teobaj

Reputation: 21

Add inlineDynamicImports: true in rollul.config.js at the export, like this:

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

Upvotes: 2

Related Questions