du7ri
du7ri

Reputation: 342

Docker run fails "return process.dlopen(module, path.toNamespacedPath(filename));"

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

Upvotes: 11

Views: 9155

Answers (2)

Alexander Sinchenko
Alexander Sinchenko

Reputation: 33

You should try to delete node_modules. This helped me.

$rm -rf node_modules/
$npm update

Upvotes: 1

Patrick Niyogitare
Patrick Niyogitare

Reputation: 138

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*

Upvotes: 12

Related Questions