mtth / avsc

Avro for JavaScript :zap:
MIT License
1.27k stars 147 forks source link

"new SlowBuffer" is deprecated since Node v.6 --> cannot use it with VITE5 and VUE3 #449

Closed Patrice-expleo closed 5 months ago

Patrice-expleo commented 7 months ago

Hi everybody,

I am updating my project from VITE4 to VITE5 using your library. Compilation is correct but in the browser got the error message: Uncaught TypeError: SlowBuffer is not a function

When I look at the stacktrace I can see you are using new SlowBuffer(1024) for var TAP. This call is deprecated since version 6 of node.

Is there a possibility for a workaround or a fix? The fix would be done very fast, cause you can use Buffer.allocUnsafeSlow instead.

I already was importing vite-plugin-node-polyfills, but that does not resolve the error.

Best regards

mtth commented 7 months ago

Your suggested fix sounds good; I'll include it in the upcoming 6.x release.

Before I backport it to 5.x - does this allow you to work around the issue?

const buffer = require('buffer');
buffer.SlowBuffer = buffer.Buffer;
Patrice-expleo commented 7 months ago

Thanks for the reply. In my case, setting the Buffer flag of vitePolyfills (in vite.config) to false will be the workaround. It is true for default.

rockwotj commented 1 month ago

@mtth did you backport this fix to 5.x? I'm running into this and having to monkey patch stuff to fix it...