linusu / buffer-from Goto Github PK
View Code? Open in Web Editor NEWA ponyfill for Buffer.from
License: MIT License
A ponyfill for Buffer.from
License: MIT License
just asking... it have been available since v5.10
An error occurs when attempting to run a react-native
project.
It is originating from index.js
, line 4.
For whatever reason, it seems like Buffer is not available in the global scope.
I was able to resolve this by adding the following before var isModern = (
if (typeof Buffer === 'undefined') {
global.Buffer = require('buffer').Buffer
}
Afterwards my project runs correctly.
Sorry for annoying you with the LICENSE topic again
installing [email protected]
npm install [email protected]
and checking the retrieved files
ls node_modules/buffer-from
turns out, that the LICENSE file is not part of the distributed module.
Only these files are present:
index.js package.json readme.md
I think it would be a good thing to include the LICENSE file with the distributed module
Triggering condition:
When Buffer.alloc
and the Buffer.allocUnsafe
function are polyfilled by other modules, and the version of node is less than v4.5.0.
Cause:
The Buffer.from
method isn't realized until v4.5.0, but it is a function befor v4.5.0.
I think you maybe already know this and use two methods ,Buffer.alloc
and Buffer.allocUnsafe
, also added in v4.5.0 as auxiliary conditions to judge if the environment is modern.
Is it better to judge the version of node or try the from
method to judge if it is really usable?
When I try to use the module (buffer from string), I get the following error: TypeError: this is not a typed array.
Using Node v4.3.2.
@LinusU Hi! I've found this package because it's used in html-tokenize
, which is used in @emotion/server
. This last package is related to server side rendering stuff and I'm trying to make it work in non-Node.js envrionments, such as Cloudflare Workers.
My problem is that this library (buffer-from) tries to access Buffer
on import. Therefore, even if the rest of the functions are never called (they are not in this scenario), the app crashes due to having Buffer undefined.
Would you consider adding typeof Buffer !== 'undefined' &&
in the logic for isModern
?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.