node-rdkafka icon indicating copy to clipboard operation
node-rdkafka copied to clipboard

Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (....)

Open lukarmar opened this issue 2 years ago • 1 comments

Environment Information

  • OS [e.g. Ubuntu 22.04.1 LTS]:
  • Node Version [e.g. 14]:
  • NPM Version [e.g. 6]:
  • C++ Toolchain [e.g. Visual Studio, llvm, g++]:
  • node-rdkafka version [e.g. 2.14.2]:

I'm following the example of the docker-alpine.md component to upload the node container, but I get an error loading shared library ld-linux-x86-64.so.2. The error appears because I export the library in my node application

Dockerfile

FROM node:14-alpine

RUN apk --no-cache add
bash
g++
ca-certificates
lz4-dev
musl-dev
cyrus-sasl-dev
openssl-dev
make
python3

RUN apk add --no-cache --virtual .build-deps gcc zlib-dev libc-dev bsd-compat-headers py-setuptools bash

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install --silent && npm cache clean --force

COPY . .

EXPOSE 3030

CMD ["npm", "run", "dev"]


Following error

 Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /usr/src/app/node_modules/node-rdkafka/build/Release/../deps/librdkafka.so.1)
      at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)
      at Module.load (internal/modules/cjs/loader.js:950:32)
      at Function.Module._load (internal/modules/cjs/loader.js:790:12)
      at Module.require (internal/modules/cjs/loader.js:974:19)
      at require (internal/modules/cjs/helpers.js:101:18)
      at bindings (/usr/src/app/node_modules/node-rdkafka/node_modules/bindings/bindings.js:112:48)
      at Object.<anonymous> (/usr/src/app/node_modules/node-rdkafka/librdkafka.js:10:32)
      at Module._compile (internal/modules/cjs/loader.js:1085:14)
      at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
      at Module.load (internal/modules/cjs/loader.js:950:32) {
      code: 'ERR_DLOPEN_FAILED'
}

lukarmar avatar Dec 27 '22 16:12 lukarmar

For me this Dockerfile works well:

FROM node:14-alpine

# Alpine and node-rdkafka
# See https://github.com/Blizzard/node-rdkafka/blob/master/examples/docker-alpine.md

RUN apk --no-cache add \
  bash \
  g++ \
  make \
  python3

RUN apk --no-cache add \
  librdkafka=1.9.2-r0 \
  librdkafka-dev=1.9.2-r0

ARG BUILD_LIBRDKAFKA=0

RUN npm i [email protected]

# We should remove deps because we use apk pkges
RUN rm -rf /node_modules/node-rdkafka/deps

nervgh avatar Apr 30 '23 13:04 nervgh