Require Buffer rather than expecting a global #132
Loading…
Reference in a new issue
No description provided.
Delete branch "kemitchell/require-buffer"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This tiny PR adds
const Buffer = require('buffer').Buffer;to the top oflib/util.js, so thatutil.jscan callBuffer.fromwithout relying onBufferbeing 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.
I just upgraded
react-scriptsto v5 and hit #68. For now, I added temporarilyglobal.Buffer = global.Buffer || require('buffer').Buffer;in my codebase, but would appreciate this PR be merged to solve the issue.@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.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.