Node.bcrypt.js: Error while building a docker image

Created on 19 Aug 2020  路  8Comments  路  Source: kelektiv/node.bcrypt.js

this is the log :

Error: Error loading shared library /home/node/app/node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: Exec format error

at Object.Module._extensions..node (internal/modules/cjs/loader.js:1206:18)

at Module.load (internal/modules/cjs/loader.js:1000:32)

at Function.Module._load (internal/modules/cjs/loader.js:899:14)

at Module.require (internal/modules/cjs/loader.js:1042:19)

at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:80:39)

at require (internal/modules/cjs/helpers.js:77:18)

at Object. (/home/node/app/node_modules/bcrypt/bcrypt.js:6:16)

at Module._compile (internal/modules/cjs/loader.js:1156:30)

at Module._extensions..js (internal/modules/cjs/loader.js:1176:10)

at Object.require.extensions. [as .js] (/home/node/app/node_modules/babel-register/lib/node.js:152:7)

at Module.load (internal/modules/cjs/loader.js:1000:32)

at Function.Module._load (internal/modules/cjs/loader.js:899:14)

at Module.require (internal/modules/cjs/loader.js:1042:19)

at Module.Hook._require.Module.require (/usr/local/lib/node_modules/pm2/node_modules/require-in-the-middle/index.js:80:39)

at require (internal/modules/cjs/helpers.js:77:18)

at Object. (/home/node/app/utils/auth.js:2:16)

2020-08-19T12:52:14: PM2 log: App [access-backend:0] exited with code [1] via signal [SIGINT]

2020-08-19T12:52:16: PM2 log: [Watch] Stop watching access-backend

2020-08-19T12:52:16: PM2 log: PM2 successfully stopped

DockerFile

FROM keymetrics/pm2:12-alpine

RUN mkdir -p /app

WORKDIR /app
ARG NODE_ENV
ENV NODE_ENV $NODE_ENV

COPY package*.json ./

RUN npm cache clean --force && rm -rf node_modules && npm install

EXPOSE 7777
CMD [ "pm2-runtime", "start", "ecosystem.config.js" ]

question

Most helpful comment

Please do not copy node_modules inside Docker. It decreases your build time and prevents this kind of errors from happening.

Use a .dockerignore and add node_modules/ to it

All 8 comments

+1

I have the same problem

+1

Please do not copy node_modules inside Docker. It decreases your build time and prevents this kind of errors from happening.

Use a .dockerignore and add node_modules/ to it

Did anyone solve this problem?

Adding node_modules to .dockerignore solved this.

docker is not detecting changes in the layers above "run npm ..." therefore it does not build the complete image. I solved it by exchanging run position with copy

I was having the same issue. Fixed by uninstalling bcrypt before building with docker, then adding bcrypt back to package.json. When you build with docker after adding bcrypt back to package.json, it should complete with no errors.

Was this page helpful?
0 / 5 - 0 ratings