Open
Description
I want to use serialize-javascript in vite project.
There are two problem,At first buffer is undefined,I install buffer,and then there is an error at randombytes,the error code is here:
//randombytes/browser.js
var crypto = global.crypto || global.msCrypto
if (crypto && crypto.getRandomValues) {
module.exports = randomBytes
} else {
module.exports = oldBrowser
}
.........
In browser,global is undefined!
I try to change it as this:
const globalThis = typeof global === 'object' ? global : window;
var crypto = globalThis.crypto || globalThis.msCrypto
if (crypto && crypto.getRandomValues) {
module.exports = randomBytes
} else {
module.exports = oldBrowser
}
And then,serialize-javascript wrok!
Metadata
Metadata
Assignees
Labels
No labels