npm install on synology gives zlib invalid distance error
Asked Answered
D

4

5

Well while this isn't ideal (yet) we're currently running a build script through synology. Part of build is of course installing all packages. However at this point a lot of errors happen.

We install using:

npm ci --only=production (though same results with npm install). And the following errors occurs:

npm WARN tar zlib: invalid distance too far back

(like many, many times) followed somewhere with:

291 verbose stack ZlibError: zlib: invalid distance too far back
291 verbose stack     at Unzip.write (/usr/local/lib/node_modules/npm/node_modules/minizlib/index.js:147:22)
291 verbose stack     at Unpack.write (/usr/local/lib/node_modules/npm/node_modules/tar/lib/parse.js:313:19)
291 verbose stack     at PassThrough.ondata (_stream_readable.js:727:22)
291 verbose stack     at PassThrough.emit (events.js:210:5)
291 verbose stack     at addChunk (_stream_readable.js:309:12)
291 verbose stack     at readableAddChunk (_stream_readable.js:290:11)
291 verbose stack     at PassThrough.Readable.push (_stream_readable.js:224:10)
291 verbose stack     at PassThrough.Transform.push (_stream_transform.js:150:32)
291 verbose stack     at PassThrough.afterTransform (_stream_transform.js:94:10)
291 verbose stack     at PassThrough._transform (_stream_passthrough.js:44:3)
291 verbose stack     at PassThrough.Transform._read (_stream_transform.js:189:10)
291 verbose stack     at PassThrough.Transform._write (_stream_transform.js:177:12)
291 verbose stack     at doWrite (_stream_writable.js:431:12)
291 verbose stack     at writeOrBuffer (_stream_writable.js:415:5)
291 verbose stack     at PassThrough.Writable.write (_stream_writable.js:305:11)
291 verbose stack     at PassThrough.ondata (_stream_readable.js:727:22)
292 verbose cwd /volume1/docker/builder/dockers/allsports.app/allsports.app.nginx/javascript
293 verbose Linux 3.10.105
294 verbose argv "/volume1/@appstore/Node.js_v12/usr/local/bin/node" "/usr/local/bin/npm" "ci"
295 verbose node v12.14.0
296 verbose npm  v6.13.4
297 error code Z_DATA_ERROR
298 error errno -3
299 error zlib: invalid distance too far back
300 verbose exit [ -3, true ]

As can be seen in the log I'm synology is using node 12.14 and npm 6.13. I've tested with exactly the same versions on my own pc and there it works smooth.

What is causing this, and can it be fixed?

Doykos answered 18/2, 2020 at 20:7 Comment(4)
Same here. I have opened a case with Synology support. I wonder if that helps...Callipygian
@Callipygian do you have a reference so I can follow any potential progress?Doykos
Right now they just want to see the logs. I'll keep you posted.Callipygian
The support will look into the problem once I give them remote access...Callipygian
R
7

The system Zlib 1.2.8 (as included in the current version of DSM by Synology) does not work with npm in Node v12 or v10, as noted at https://github.com/nodejs/node/issues/22839#issuecomment-474484250

Synology's earlier versions of Node (e.g. v8) do not have this issue and npm works normally. I just ran across this error (npm can't do anything useful) with Node v12 on my Synology and backing off to Node v8 does make the issue go away.

One option might be to build a newer zlib from source using Entware, but I've read that Synology support refuse to even touch a system with ipkg/Optware/Entware on it. The changelog for Zlib indicates a number of portability improvements in 1.2.9, but I'm not sure if just replacing the system zlib would cause issues with other software on the system.

Overall, if your build script can handle Node 8 (which just went EOL unfortunately) I would stick with that for now. Otherwise the official/supported answer is presumably to wait for an update to DSM from Synology.

Restore answered 25/2, 2020 at 22:40 Comment(1)
Well we've just moved the whole build system to a temporary docker. A lot of time and complexity further but no longer depend on an outdated node version. (Which was the goal in the first place).Doykos
T
2

So I replace the 1.2.8 zlib to a 1.2.11 one then npm works now.

I use the libz.so.1.2.11 come from entware, but entware only install in /opt/lib so I copy it to /lib

rm /lib/libz.so.1.2.8
rm /lib/libz.so.1
rm /lib/libz.so

cp /opt/lib/libz.so.1.2.11 /lib/
chmod +x /lib/libz.so.1.2.11
ln -s /lib/libz.so.1.2.11 /lib/libz.so.1
ln -s /lib/libz.so.1.2.11 /lib/libz.so

I never upgrade DSM so I think it should be fine.

Tailor answered 19/3, 2020 at 15:35 Comment(3)
just tested it on a DS718+ with DSM 6.2.3 : it works fineLengel
DSM 6.2.3 for the DS412+ does not contain an updated version of libz.so. It is still at 1.2.8.Pettaway
So on DS412+ this platform you will still need entware. Note: Be very careful if you do the above libz.so update. You need to replace the libz.so as root. If you try to do the above commands using sudo you are in for a nasty surprise, as your sudo command will stop working when the libz.so file is removed. I experienced this in Feb 2020, and it required a total DSM reinstall to get back in operation again.Pettaway
A
1

May it help to switch the node version temporarily? This works if you have the V12 and V8 packages installed.

sudo -i 
nvm ls # all installed versions
nvm set 8.9.4
node --version
npm --version
# do things with v8
nvm set 12.14.0

Unfortunately I'm not allowed to comment, so @StonyBoy: You may copy the zlib from entware e.g. to /volume1/etc/lib and then start npm with a script:

#!/bin/bash
LD_LIBRARY_PATH=/volume1/etc/lib:/usr/local/lib:/usr/lib:/lib:/lib/security
export LD_LIBRARY_PATH
exec /usr/local/bin/npm $@

This avoids those annoying reinstalls ...

Aksum answered 7/5, 2020 at 21:39 Comment(0)
C
0

It's very dangerous to change libs located in /lib or /usr/lib (same on my system). I did it and it breaked booting my Synology. Needed to restore firmware and costs me lot of nerves ...

Unfortunately entware libs stopped working on my Synology RS816 (MARVELL Armada 385 88F6820, armv7l) since a firmware update (I not sure which, right now I have 6.2.3-25426). If I try to run npm I get

error while loading shared libraries: /opt/lib/libz.so.1: internal error

Not sure, but I think it's because libz is not statically linked and uses /opt/lib/libc.so.6 and this breaks it somehow.

So I searched for another libz.so.1.2.11 and found one at optware-ng, copied that to /usr/local/lib and made a new npm script. On my RS816 npm is located at /usr/local/bin and was symlinked to ../lib/node_modules/npm/bin/npm-cli.js. The new npm script is similar to (Kein Admin) and looks like that:

#!/bin/sh
# fix npm WARN tar zlib: invalid distance too far back
# using libz 1.2.11 from optware-ng located at /usr/local/lib
export LD_LIBRARY_PATH=/usr/local/lib:/lib
/usr/local/lib/node_modules/npm/bin/npm-cli.js $@
Ciaphus answered 12/6, 2020 at 21:11 Comment(3)
this looks like a promising path, but what exactly am I doing with this script? Does it replace the old npm (in your case in /usr/local/bin)?Ladner
/usr/local/bin/npm was a symlink to /usr/local/lib/node_modules/npm/bin/npm-cli.js. So I removed the symlink and added the script instead.Ciaphus
ok, that wasn't too hard to understand... sorry and thanks.Ladner

© 2022 - 2024 — McMap. All rights reserved.