adm-zip
adm-zip copied to clipboard
Process version undefined
Hi, I use this package in a Cypress cy.task to simply unzip.
After the 0.5.10 version the following code has an issue:
Cannot read properties of undefined (reading 'split')
at ./node_modules/adm-zip/methods/inflater.js (webpack:///./node_modules/adm-zip/methods/inflater.js:1:44)
at __webpack_require__ (webpack:///webpack/bootstrap:19:0)
at ./node_modules/adm-zip/methods/index.js (webpack:///./node_modules/adm-zip/methods/index.js:2:0)
at __webpack_require__ (webpack:///webpack/bootstrap:19:0)
at ./node_modules/adm-zip/zipEntry.js (webpack:///./node_modules/adm-zip/zipEntry.js:4:14)
at __webpack_require__ (webpack:///webpack/bootstrap:19:0)
at ./node_modules/adm-zip/adm-zip.js (webpack:///./node_modules/adm-zip/adm-zip.js:3:17)
at __webpack_require__ (webpack:///webpack/bootstrap:19:0)
Tracing it this code has the issue:
const version = +(process.versions ? process.versions.node : "").split(".")[0] || 0;
The process.versions is empty somehow in my case, so the process.versions.node is undefined.
This is happening if process browser shim is used (https://github.com/defunctzombie/node-process). It defines process.versions as empty object, causing split function to fail.
I'm also experiencing this issue while running with Cypress.
adm-zip: 0.5.16 cypress: 13.14.1
Unfortunately I've also encountered this issue, and have to use the following patch as a workaround:
adm-zip+0.5.16.patch:
diff --git a/node_modules/adm-zip/methods/inflater.js b/node_modules/adm-zip/methods/inflater.js
index 8769e66..a990c52 100644
--- a/node_modules/adm-zip/methods/inflater.js
+++ b/node_modules/adm-zip/methods/inflater.js
@@ -1,4 +1,4 @@
-const version = +(process.versions ? process.versions.node : "").split(".")[0] || 0;
+const version = +(process.versions ? process.versions.node ?? "" : "").split(".")[0] || 0;
module.exports = function (/*Buffer*/ inbuf, /*number*/ expectedLength) {
var zlib = require("zlib");
@cthackers Could someone with access apply @craiganderson-iotv fix? It's super simple and works fine.