nodejs / unofficial-builds

Unofficial binaries for Node.js
https://unofficial-builds.nodejs.org
242 stars 50 forks source link

Musl-based NodeJS won't start on Alpine Linux without libstdc++ #27

Closed breun closed 3 years ago

breun commented 3 years ago

The musl-based NodeJS tarball doesn't work on a vanilla Alpine Linux image out of the box:

% docker run -it --rm alpine
/ # wget https://unofficial-builds.nodejs.org/download/release/v14.16.1/node-v14.16.1-linux-x64-musl.tar.gz
Connecting to unofficial-builds.nodejs.org (45.55.98.129:443)
saving to 'node-v14.16.1-linux-x64-musl.tar.gz'
node-v14.16.1-linux- 100% |********************************************************************************************************************************| 32.7M  0:00:00 ETA
'node-v14.16.1-linux-x64-musl.tar.gz' saved
/ # tar zxf node-v14.16.1-linux-x64-musl.tar.gz
/ # cd node-v14.16.1-linux-x64-musl
/node-v14.16.1-linux-x64-musl # ./bin/node --version
Error loading shared library libstdc++.so.6: No such file or directory (needed by ./bin/node)
Error loading shared library libgcc_s.so.1: No such file or directory (needed by ./bin/node)
Error relocating ./bin/node: _ZNSt7__cxx1118basic_stringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode: symbol not found
Error relocating ./bin/node: _ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE9push_backEc: symbol not found
Error relocating ./bin/node: _ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE: symbol not found
(...)

It seems NodeJS needs Alpine's libstdc++ package to be installed:

/node-v14.16.1-linux-x64-musl # apk add libstdc++
/node-v14.16.1-linux-x64-musl # ./bin/node --version
v14.16.1

Is this already documented somewhere? If not, what would be a good spot?

nschonni commented 3 years ago

There are already the official images https://github.com/nodejs/docker-node that show how it needs to be setup (even if you don't want to pull them for some reason)

breun commented 3 years ago

I see https://github.com/nodejs/docker-node/blob/main/Dockerfile-alpine.template indeed installs the libstdc++ package on Alpine, but I don't generally don't come across a Dockerfile in another repository when I'm looking for documentation. :)

We could add a sentence/section about this requirement to the README.md in this repository?

rvagg commented 3 years ago

That's a great idea @breun, would you mind PR'ing that?