-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Use buffer module which support node.js and browser #31
Conversation
hyperid.js
Outdated
@@ -3,7 +3,7 @@ | |||
const uuidv4 = require('./uuid') | |||
const parser = require('uuid-parse') | |||
const maxInt = Math.pow(2, 31) - 1 | |||
const Buffer = require('buffer').Buffer | |||
const Buffer = require('buffer/').Buffer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const Buffer = require('buffer/').Buffer | |
const Buffer = require('buffer/').Buffer |
Please use the global Buffer
object if it is available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function loadBuffer () {
const b = require('buffer')
// use third party module if no Buffer module
return b
? b.Buffer
: require('buffer/').Buffer
}
I have added a function to load Buffer, please review my new commit if have time.
Why was this closed? |
thiw now conflicts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This should really include a test |
Let me think about how to add test for this case. |
closing for no activity |
The Wepack5 haven't provided polyfills for node.js core modules, and Vite does't suppot polyfill for buffer.
It will occur error on browser using the Wepack5 and Vite.
Because of the Browserify have used buffer polyfill, it is fine on browser.
I would suggest using buffer polyfill by add npm module buffer like Browserify.
link: #9 (comment)
reproduction:
Webpack5: https://stackblitz.com/edit/node-yctv93?file=src%2Findex.js,package.json
Vite: https://stackblitz.com/edit/node-bedrwr?file=package.json