簡體   English   中英

為什么我在使用帶有 Angular 8 的 Pdfmake 時收到“未處理的 promise 拒絕類型錯誤:null 不是函數”?

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

我正在使用 PDFmake 在 Angular 應用程序中生成 pdf 文件。 我能夠使用 pdfmake 庫生成所有必需的結果。

但是我在控制台日志中收到“未處理的 promise 拒絕類型錯誤:null 不是函數”這個錯誤,如下所示。

在此處輸入圖像描述

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`);

您需要提供導致此錯誤的行的代碼片段。 但是我相信您沒有處理 promise 的reject()塊需要提供一個catch塊來處理 promise 拒絕的情況。

對於 angular v9.0.5將 pdfMake 從v0.2.4降級v0.1.70時,我遇到了同樣的錯誤,它可以消除錯誤。 也許新版本的 pdfMake 與舊的 angular 版本不兼容。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM