shikijs / shiki

A beautiful yet powerful syntax highlighter
http://shiki.style/
MIT License
9.19k stars 330 forks source link

WASM usage with getHighlighterCore errors with Buffer.isBuffer (this doesn't exist in the browser) #664

Closed NullVoxPopuli closed 2 months ago

NullVoxPopuli commented 2 months ago

Validations

Versions

"@shikijs/rehype": "^1.2.0",
"shiki": "^1.2.0",

Describe the bug

image

and the entrypoint is from this path: image

I will be working around this for now by defining Buffer.isBuffer on window/globlaThis via this in my index.html

globalThis.Buffer = { isBuffer: () => false }

Reproduction

call await getHighlighterCore({

Contributes

antfu commented 2 months ago
Screenshot 2024-04-29 at 13 02 47

But the case is that Buffer should not exist in browser (we already do the check before calling Buffer.isBuffer - are you doing some shimming for your client? I don't mind doing an extra check of the Buffer.isBuffer?() if that helps

NullVoxPopuli commented 2 months ago

I see this: image

which is probably because Webpack is doing something silly -- not sure I can have control over it in this case :thinking: I don't have any explicit configuration that would add this ... a blank Buffer object :thinking:

I don't mind doing an extra check of the Buffer.isBuffer?() if that helps

It would!

antfu commented 2 months ago

Would you like to send a quick PR? Thanks

NullVoxPopuli commented 2 months ago

ye! https://github.com/shikijs/shiki/pull/666