Skip to content

Error: "PDFDocument is not a constructor" with Webpack #1654

@bgsa

Description

@bgsa

Question

PdfKit works fine on localhost but when I bundle it with webpack, the error PDFDocument is not a constructor is thrown on line "new PDFDocument()".

Description

It works if I bundle with NCC.
I guess it is related to webpack.

Code sample

const PDFDocument = require('pdfkit');
const pdf = new PDFDocument(); // <-- error

Your environment

  • pdfkit version: 0.17 (latest version)
  • Node version: 22
  • Browser version (if applicable): Serverless App
  • Operating System: AWS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions