-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vite Packing error vfs_fonts #2654
Comments
I'm having the same error when building my code import * as pdfFonts from "pdfmake/build/vfs_fonts";
import * as pdfMake from "pdfmake/build/pdfmake";
(<any>pdfMake).vfs = pdfFonts.pdfMake.vfs; versios "pdfmake": "^0.2.8",
"react": "^18.2.0",
"typescript": "^5.0.2",
"vite": "^4.4.5" console output npm run build
vite v4.4.8 building for production...
src/components/pdf-make/index.ts (72:15) "pdfMake" is not exported by "node_modules/pdfmake/build/vfs_fonts.js", imported by "src/components/pdf-make/index.ts". |
Interim SolutionI created the file original code this.pdfMake = this.pdfMake || {}; this.pdfMake.vfs = {"Roboto-Italic.ttf":"AAEAAAARA ... AA0AA1AAA="}; sample my code export default { "Roboto-Italic.ttf": "AAEAAAARAQAABAAQR0RFRqbz ... 0AjQAwAJgAmwAxANAA0AA1AAA="}; sample my code import * as pdfFonts from "./vfs_fontes"; // 👈 local import
import pdfMake from "pdfmake/build/pdfmake";
(<any>pdfMake).vfs = pdfFonts.default; Another simpler solution is to download the source from the CDN import pdfMake from "pdfmake/build/pdfmake";
(<any>pdfMake).fonts = {
Roboto: {
normal:
"https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Regular.ttf",
bold: "https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Medium.ttf",
italics:
"https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-Italic.ttf",
bolditalics:
"https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.66/fonts/Roboto/Roboto-MediumItalic.ttf",
},
}; @Kimser this is what worked for me, for now I will use it this way and monitor this problem until a definitive solution is found. |
@izidorio approach works, but it gives me an error as we're trying to mutate the import:
The safe way I found to do it is by passing down our vfs fonts as an argument to createPdf (you can see it is supported, based on @types/pdfmake): So the change is the following, instead of this: import { vfs_fonts } from './vfs_fonts';
(<any>pdfMake).vfs = pdfFonts.default; do this: import * as pdfMake from 'pdfmake/build/pdfmake.js';
import { vfs_fonts } from './vfs_fonts';
....
pdfMake.createPdf(docDefinition, undefined, undefined, vfs_fonts).download(); Now the app works as expected in dev mode, but also after building it. |
import pdfMake from "pdfmake/build/pdfmake"; export const generatePDFClient = (data) => { return new Promise((resolve, reject) => {
|
This removes the VFS fonts because they fail to build with Vite (and likely also with Rollup, which Vite uses under the hood). See bpampuch/pdfmake#2654 for some potential ideas to resolve this.
This removes the VFS fonts because they fail to build with Vite (and likely also with Rollup, which Vite uses under the hood). See bpampuch/pdfmake#2654 for some potential ideas to resolve this.
it worked for me also like this! just thet fact to create a vfs_fotns.ts file with this structure:
and import it directly in my code base. where:
|
Interim Solution for Vite+React+JS
|
@habeebijaba works for me ;)) |
thank you bro it worked for me |
In version 0.2.15 changed VFS format. (Custom VFS files require rebuild.) Now works this simple import: import pdfMake from "pdfmake/build/pdfmake";
import "pdfmake/build/vfs_fonts"; (Tested on vite + react jsx.) Other way for frameworks where not available global can be used: import pdfMake from "pdfmake/build/pdfmake";
import pdfFonts from "pdfmake/build/vfs_fonts";
pdfMake.addVirtualFileSystem(pdfFonts); or see documentation |
The text was updated successfully, but these errors were encountered: