Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReferenceError: Buffer is not defined #2758

Open
shuaybi opened this issue May 20, 2024 · 0 comments
Open

ReferenceError: Buffer is not defined #2758

shuaybi opened this issue May 20, 2024 · 0 comments

Comments

@shuaybi
Copy link

shuaybi commented May 20, 2024

Why is the code using Buffer when running inside a browser?

When creating a PDFDocument I get the following error in the browser console:

pdfkit.js:441 Uncaught (in promise) ReferenceError: Buffer is not defined
at wordArrayToBuffer2 (pdfkit.js:441:3)
at Function.generateFileID (pdfkit.js:454:12)
at new PDFDocument2 (pdfkit.js:38748:29)

Seems to be coming from the module pdfkit.js

I am using version 3.4.4 of the library.

I am trying to generate pdf in the browser. Isn't Buffer only available in Node? Why is the code using Buffer when running inside a browser?

Using Chrome Browser: Version 124.0.6367.208 (Official Build) (arm64)

Workaround:

I installed buffer (npm install buffer) and then added the following to my index.js file:

window.Buffer = window.Buffer || require("buffer").Buffer;

@shuaybi shuaybi changed the title Error: Uncaught (in promise) ReferenceError: Buffer is not defined ReferenceError: Buffer is not defined May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant