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?

paul23
  • 8,799
  • 12
  • 66
  • 149

4 Answers4

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.

Joseph Riesen
  • 288
  • 1
  • 4
  • 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). – paul23 Feb 25 '20 at 22:53
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.

Sam Nya
  • 31
  • 4
  • just tested it on a DS718+ with DSM 6.2.3 : it works fine – Xavave May 12 '20 at 14:53
  • DSM 6.2.3 for the DS412+ does not contain an updated version of libz.so. It is still at 1.2.8. – StonyBoy May 24 '20 at 12:52
  • 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. – StonyBoy May 24 '20 at 12:59
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 ...

Kein Admin
  • 11
  • 3
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 $@
acoder
  • 126
  • 1
  • 5
  • 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``)? – Robert Oct 22 '20 at 11:44
  • `/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. – acoder Oct 23 '20 at 19:02
  • ok, that wasn't too hard to understand... sorry and thanks. – Robert Nov 11 '20 at 14:13