toString error with zlib starting with 0.18.0
sean-daley opened this issue · 2 comments
We recently tried upgrading our project to 0.19.0 and ran into the following error (or a similar one at least):
chunk-D6GJMSXT.js?v=90ce99c2:13897 Uncaught TypeError: Cannot read properties of undefined (reading 'toString')
at node_modules/browserify-zlib/lib/index.js (chunk-D6GJMSXT.js?v=90ce99c2:13897:100)
at __require (chunk-7QXJ7KUB.js?v=90ce99c2:2089:50)
at node_modules/fast-zlib/index.js (fast-zlib.js?v=fcc884ed:2099:16)
at __require (chunk-7QXJ7KUB.js?v=90ce99c2:2089:50)
at fast-zlib.js?v=fcc884ed:2217:16
After downgrading a little bit, it looks like this was introduced in 0.18.0. Everything works just fine below that. Unfortunately for us, we now hit an OOM error with vitest that, based on reading the issues here, is probably fixed in 0.19.0 so for now we are stuck on 0.9.0.
I tried using stackblitz to create a reproducible setup but was not able to get it working there. I was able to create a mini github repo though that experiences the issue.
https://github.com/sean-daley/vite-zlib-test
Just npm install && npm run dev
to see the issue.
If you drop vite-plugin-node-polyfills back down to 0.17.0, the problem goes away.
It looks like the lines that are causing the blowup in browserify-zlib are:
var kMaxLength = require_dist().kMaxLength;
var kRangeErrorMessage = "Cannot create final Buffer. It would be larger than 0x" + kMaxLength.toString(16) + " bytes";
It seems like kMaxLength is missing here?
This might be a dupe of #75 but I ended up opening a separate issue just in case it wasn't. Though now that I re-read that one again, I'm pretty sure this at least overlaps that one.
This has been released in v0.21.0
.