question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pdfkit import fails in Electron

See original GitHub issue

Bug Report

Description of the problem

I am trying to import pdfkit in Electron. I have been using Pdfkit in Node.js without trouble so far, but my Electron application will not run after I add the import.

Code sample

import PDFDocument from 'pdfkit';

I receive the following error:

    at createError (electron/js2c/asar.js:126)
    at Object.fs.readFileSync (electron/js2c/asar.js:545)
    at Object../node_modules/fontkit/index.js (ArabicShaper.js:5)
    at __webpack_require__ (bootstrap:789)
    at fn (bootstrap:100)
    at Module../node_modules/pdfkit/js/pdfkit.es5.js (index.js:20)
    at __webpack_require__ (bootstrap:789)
    at fn (bootstrap:100)
    at Module../src/renderer/lib/exportToPdf.ts (exportToPdf.ts:3)
    at __webpack_require__ (bootstrap:789)

Your environment

  • pdfkit version: 0.11.0
  • Electron version: 9.0.4
  • Node version: 12.14.1
  • Browser version (if applicable): Chromium 83.0.4103.104
  • Operating System: Windows 10

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
blikblumcommented, Jun 17, 2020

Can you try pdfkit-next?

It load resources in a browser friendly way. ( Not sure about electron )

0reactions
blikblumcommented, Aug 1, 2021

There’s a webpack 5 example at https://github.com/foliojs/pdfkit/tree/master/examples/webpack. It should work with electron

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use PDFkit library with webpack? - Stack Overflow
I've seen that many users are having issues with fs core module and webpack - and i tried every solution i could find....
Read more >
PDFKit
PDFKit is a PDF document generation library for Node and the browser that makes creating complex, multi-page, printable documents easy.
Read more >
Electron PDF SDK — Fast Setup, 100+ features - PSPDFKit
Integrate Electron PDF SDK to quickly deploy out-of-the-box features across macOS, Windows, Linux. Add PDF viewing, editing, form filling, ...
Read more >
Generating PDF Files in Node.js with PDFKit - Stack Abuse
In this tutorial, we'll see how to generate PDF files in Node.js using PDFKit, how to customize them, align text, add images, scale...
Read more >
How to include Node modules with Webpack
I had a similar problem in a project using Webpack, Electron, and Angular. ... You tried to require a Node module instead of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found