bpampuch / pdfmake

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

Cannot read property 'pdfMake' of undefined #1459

Closed MarkSalabutin closed 5 years ago

MarkSalabutin commented 5 years ago

On application start I have this error: image

liborm85 commented 5 years ago

How to use pdfmake is described in readme in Getting Started section and see how to use in javascript frameworks.

MarkSalabutin commented 5 years ago

I've already done this, but I still have this error

liborm85 commented 5 years ago

You do not include pdfmake to your script. Without some informations, and sample of your code, can not help. You use some js framework?

MarkSalabutin commented 5 years ago

Yes, I'm using React.js. That's how I init pdfmake package import pdfMake from "pdfmake/build/pdfmake"; import pdfFonts from "pdfmake/build/vfs_fonts"; pdfMake.vfs = pdfFonts.pdfMake.vfs;

jamesond commented 5 years ago

@MarkSalabutin did you ever figure this out?

liborm85 commented 5 years ago

Your usage is from example in readme, and it works correctly. If not, problem will be in react application, try to ask on react support.

poomarimuruganD commented 5 years ago

@MarkSalabutin You using this import method. This is work for me. import as pdfMake from 'pdfmake/build/pdfmake'; import as pdfFonts from 'pdfmake/build/vfs_fonts'; pdfMake.vfs = pdfFonts.pdfMake.vfs;

MarkSalabutin commented 5 years ago

There was a problem in my bundler. I shouldn't compile dependencies.

madmacc commented 4 years ago

@poomarimuruganD That worked for me. Thanks.

merrakokebie commented 1 year ago

You using this import method. This is work for me. import as pdfMake from 'pdfmake/build/pdfmake'; import as pdfFonts from 'pdfmake/build/vfs_fonts'; pdfMake.vfs = pdfFonts.pdfMake.vfs;

This worked for me and saved me so much time!! Thank you!

DmytroShvetsovDevPro commented 1 year ago

Hi @MarkSalabutin, I know it's been a while, but maybe you can share what particularly have you updated to get rid of this issue? I started facing this issue during my unit-tests run after installing completely another package. And now I'm wondering what should I update to make it work. Thanks in advance!

merrakokebie commented 1 year ago

Hello, I will be glad to help out, what I did is, instead of doing the import like the commented out way, I used "import * as" which resolved my issue. For all the solution except this, I used this site:https://www.ngdevelop.tech/angular-8-export-to-pdf-using-pdfmake/

Let me know if your issue is resolved! //import {pdfMake} from 'pdfmake/build/pdfmake';

//import {pdfFonts} from 'pdfmake/build/vfs_fonts';

 

import * as pdfMake from 'pdfmake/build/pdfmake';

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

pdfMake.vfs = pdfFonts.pdfMake.vfs;

On Friday, August 5, 2022 at 05:59:53 AM CDT, Dmytro Shvetsov ***@***.***> wrote:  

Hi @MarkSalabutin, I know it's been a while, but maybe you can share what particularly have you updated to get rid of this issue? I started facing this issue during my unit-tests run after installing completely another package. And now I'm wondering what should I update to make it work. Thanks in advance!

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

DmytroShvetsovDevPro commented 1 year ago

Hi @merrakokebie! Thanks a lot for your response! Unfortunately, your suggestion didn't resolve my issue. By the way, I'm using precisely your way of importing and initialising pdf-stuff in my React-component. I don't have troubles during my development or running the app. Issue was occurred on stage of unit-testing and for current moment I'm not sure way. Some time ago I read something about NodeJS versions (because in our project we use pretty old v12), so maybe bumping up NodeJS version will help me, but for now I just skip broken tests :( I'll come back to you with updates, if I find appropriate solution, to share with you.

merrakokebie commented 1 year ago

Ok. Thank you for the update. I hope Node js update will work for you. I am using the latest node. Merra

On Mon, Aug 8, 2022 at 4:54 AM, Dmytro @.***> wrote:

Hi @merrakokebie! Thanks a lot for your response! Unfortunately, your suggestion didn't resolve my issue. By the way, I'm using precisely your way of importing and initialising pdf-stuff in my React-component. I don't have troubles during my development or running the app. Issue was occurred on stage of unit-testing and for current moment I'm not sure way. Some time ago I read something about NodeJS versions (because in our project we use pretty old v12), so maybe bumping up NodeJS version will help me, but for now I just skip broken tests :( I'll come back to you with updates, if I find appropriate solution, to share with you.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

nawangwe commented 1 year ago

@merrakokebie did you manage to find a solution to this?

victorbr988 commented 1 year ago

estou tendo um problema parecido:

"TypeError: Cannot read properties of undefined (reading 'vfs')"

e estou iniciando o arquivo com

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

pdfMake.vfs = pdfFonts.pdfMake.vfs;
jamalludin02 commented 7 months ago

FINALLY THIS CODE WORKED FOR ME 😪

import * as pdfMake from 'pdfmake/build/pdfmake';
import * as jszip from 'jszip';

pdfMake.vfs = {};
pdfMake.jszip = jszip;
pdfMake.DynamicContent = {
    content: {
        widths: '100%'
    }
};
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'
    },
};

export default pdfMake;
semihpro commented 2 weeks ago

Guys I just coppied roboto object from route and put it in a js file and just used it, Here my code,

import * as pdfMake from "pdfmake/build/pdfmake";
import roboto from "../../../assets/fonts/roboto.js"
pdfMake.vfs = roboto;

my robot.js file like below

export default{
  "Roboto-Italic.ttf": "AAEAAAARAQAABAAQR0RFRqbzo4gAAddgAAACWEdQT1N/jKrdAAHZuAAAWMBHU1VCm18k/
....}
Nurai1 commented 2 weeks ago

And this after import also works: pdfMake.vfs = window.pdfMake.vfs