skip to Main Content

im trying to make a dockerfile and run my code into this container. im getting following error:

node:internal/modules/cjs/loader:1187
  return process.dlopen(module, path.toNamespacedPath(filename));
                 ^

Error: /node_modules/bcrypt/lib/binding/napi-v3/bcrypt_lib.node: invalid ELF header
    at Object.Module._extensions..node (node:internal/modules/cjs/loader:1187:18)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/node_modules/bcrypt/bcrypt.js:6:16)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12) {
  code: 'ERR_DLOPEN_FAILED'
}

My application works fine without docker.
i also tryed to remove bcrypt like in this question: Node – was compiled against a different Node.js version using NODE_MODULE_VERSION 51

dockerfile:

FROM node:16
WORKDIR ./
COPY package*.json ./
RUN npm install 
COPY . .
EXPOSE 4000
CMD ["node", "server.js"]

.dockerignore:

node_modules
upload
export
converage
.git
.tmp
.vscode
.github
.env

2

Answers


  1. You need to add a .dockerignore

    The basic .dockerignore look like

    # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
    
    # dependencies
    /node_modules
    /.pnp
    .pnp.js
    
    # testing
    /coverage
    
    # production
    /build
    
    # misc
    .DS_Store
    .env.local
    .env.development.local
    .env.test.local
    .env.production.local
    
    npm-debug.log*
    yarn-debug.log*
    yarn-error.log*
    
    Login or Signup to reply.
  2. You should try to delete node_modules. This helped me.

    $rm -rf node_modules/
    $npm update
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search