简体   繁体   中英

Why I am getting "Unhandled promise rejection TypeError: null is not a function" when using Pdfmake with Angular 8?

I am using PDFmake to generate pdf files in the Angular application. I am able to generate all the required results using pdfmake library.

But I am getting 'Unhandled promise rejection TypeError: null is not a function' this error in the console log as shown below.

在此处输入图像描述

pdfmake.js:31998 Unhandled promise rejection TypeError: null is not a function
    at __webpack_modules__.9662.module.exports (pdfmake.js:29878:1)
    at new Promise (pdfmake.js:36500:1)
    at ZoneAwarePromise.then (zone.js:1034:1)
    at pdfmake.js:36565:1
    at new Promise (pdfmake.js:36504:1)
    at ZoneAwarePromise.then (pdfmake.js:36564:1)
    at push../node_modules/@angular/platform-browser/fesm5/animations.js.AnimationRendererFactory._scheduleCountTask (animations.js:152:1)
    at animations.js:181:1
    at push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391:1)
    at push../node_modules/zone.js/dist/zone.js.Zone.run (zone.js:150:1)
module.exports @ pdfmake.js:31998
dispatchEvent @ pdfmake.js:36416
(anonymous) @ pdfmake.js:36429
module.exports @ pdfmake.js:33533
(anonymous) @ pdfmake.js:36426
queue.<computed> @ pdfmake.js:34218
run @ pdfmake.js:34194
listener @ pdfmake.js:34205
const documentDefinition = {
  content: [
    {
      table: {
        widths: [100, '*', 200, '*'],
        body: [
          ['width=100', 'star-sized', 'width=200', 'star-sized'],
          [
            'fixed-width cells have exactly the specified width',
            { text: 'nothing interesting here', italics: true, color: 'gray' },
            { text: 'nothing interesting here', italics: true, color: 'gray' },
            { text: 'nothing interesting here', italics: true, color: 'gray' },
          ],
        ],
      },
    },
  ],
  pageSize: 'A4',
  pageOrientation: 'landscape',
  pageMargins: [20, 30, 20, 30],
};
pdfMake.createPdf(documentDefinition).download(`myPDF.pdf`);

You need to provide code snippet of the line causing this error. But I believe that you didn't handle the case where your promise 's reject() block you need to provide a catch block to handle promise rejection.

I had the same error downgrading pdfMake from v0.2.4 to v0.1.70 for angular v9.0.5 did the trick for getting rid of the error. Maybe the new version pdfMake isn't compatible with the old angular version.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM