adm-zip icon indicating copy to clipboard operation
adm-zip copied to clipboard

Process version undefined

Open katalinszenas opened this issue 1 year ago • 2 comments

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.

katalinszenas avatar Aug 12 '24 15:08 katalinszenas

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.

linasburneika avatar Sep 03 '24 13:09 linasburneika

I'm also experiencing this issue while running with Cypress.

adm-zip: 0.5.16 cypress: 13.14.1

mgentry612 avatar Sep 04 '24 18:09 mgentry612

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");

craiganderson-iotv avatar Dec 12 '24 03:12 craiganderson-iotv

@cthackers Could someone with access apply @craiganderson-iotv fix? It's super simple and works fine.

gustawx avatar Jun 20 '25 09:06 gustawx