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

Require Buffer rather than expecting a global #132

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kemitchell
Copy link

@kemitchell kemitchell commented Dec 21, 2021

This tiny PR adds const Buffer = require('buffer').Buffer; to the top of lib/util.js, so that util.js can call Buffer.from without relying on Buffer being a global. This allows code bundlers and other static analyzers to detect the use of Buffer and shim it (e.g. with npm:buffer) if it is not part of the target environment, such as when bundling for web browsers.

I suspect this approach might satisfy some of the people describing hold-ups in #68. I have been able to use this fork to bundle gray-matter with esbuild without error.

I would be comfortable publishing this with a patch-level version bump.

@firmart
Copy link

firmart commented Dec 23, 2021

I just upgraded react-scripts to v5 and hit #68. For now, I added temporarily global.Buffer = global.Buffer || require('buffer').Buffer; in my codebase, but would appreciate this PR be merged to solve the issue.

@segevfiner
Copy link

@jonschlinkert Are you still maintaining this library? It would be quite helpful to get this merged so it can work with modern WebPack 5+, Vite, and so on, which no longer include node shims by default. There are also several other PRs that help keep this library in shape that you might want look at.

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

Successfully merging this pull request may close these issues.

3 participants