Skip to content

Can't used in browser? #134

Open
Open
@cx690

Description

@cx690

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions