bpampuch / pdfmake

Client/server side PDF printing in pure JavaScript
http://pdfmake.org
Other
11.46k stars 2.03k forks source link

TypeError: Cannot redefine property: vfs #2716

Open vinch opened 2 months ago

vinch commented 2 months ago

Hello. I'm using pdfmake in a SvelteKit (1.20) project in TypeScript and simply doing the imports via the method presented in the documentation gives me an error.

I'm doing this :

import * as pdfMake from "pdfmake/build/pdfmake";
import * as pdfFonts from 'pdfmake/build/vfs_fonts';

(<any>pdfMake).vfs = pdfFonts.pdfMake.vfs;

And I get the following error :

TypeError: Cannot redefine property: vfs

What am I doing wrong?

YTDev commented 2 months ago

Try to add this to rollup config: .... build: { rollupOptions: {

    context: "window",
    moduleContext: (id) => {
      if (id.includes('pdfmake/build/vfs_fonts.js')) {
        return 'window';
      }
    },
  },
},