node.bcrypt.js icon indicating copy to clipboard operation
node.bcrypt.js copied to clipboard

Application Crashing When Using bcrypt's compare function on node docker image

Open rubemarjrtech opened this issue 1 year ago • 6 comments

Title: Application Crash with bcrypt's compare function on node docker image

Description: I ran into an issue where my application crashes when using the compare function from bcrypt on the node Docker image. Here are the details:

Steps to Reproduce: Use the node Docker image in a Node.js application. Utilize bcrypt's compare function to compare hashed passwords. Observe the application crash upon invoking the compare function.

Expected Behavior: The application should successfully execute the compare function without crashing.

Actual Behavior: The application crashes when calling the compare function without throwing any specific error.

Additional Details:

Dockerfile:

FROM node

WORKDIR /home/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 4000

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

and this is my docker-compose.yml:

version: '3'

networks:
   local:

services:
   mysql:
      container_name: mysqldb
      image: mysql:8
      environment:
         MYSQL_DATABASE:
         MYSQL_USER:
         MYSQL_PASSWORD:
         MYSQL_ROOT_PASSWORD:
      networks:
         - local
      ports:
         - '3306:3306'

   app:
      depends_on:
         - mysql
      container_name: blog-api
      build:
         context: .
         dockerfile: Dockerfile
      environment:
         DB_HOST:
         DB_USERNAME:
         DB_PASSWORD:
         DB_DATABASE:
      volumes:
         - ./:/home/app
      ports:
         - '4000:4000'
      networks:
         - local

I read on this issue it could be a library mismatch, but I tried using a .dockerignore file and nothing changed.

Any suggestion on what I could do?

rubemarjrtech avatar Aug 20 '24 14:08 rubemarjrtech

same problem here node:20-alpine, any workaround please?

kopax avatar Sep 24 '24 14:09 kopax

use 5.1.0

segadora avatar Oct 03 '24 08:10 segadora

same problem here node:20-alpine, any workaround please?

what I did to fix this problem was:

  • changed docker-compose, from version '3' to version: '3.5'
  • Dockerfile first COPY step to COPY ./package.json .
  • added a volume for node_modules, so following my own post it would be:

volumes: - ./:/home/app - /home/app/node_modules

instead of just:

volumes: - ./:/home/app

and ran docker-compose build before docker-compose up

rubemarjrtech avatar Oct 03 '24 19:10 rubemarjrtech

same problem with hashSync() when built on node:20-alpine

stepskop avatar Oct 19 '24 10:10 stepskop

same problem with hashSync() when built on node:20-alpine

look at my answer above your comment and see if anything I changed in my compose file helps you.

rubemarjrtech avatar Oct 20 '24 22:10 rubemarjrtech

same problem with hashSync() when built on node:20-alpine

look at my answer above your comment and see if anything I changed in my compose file helps you.

I understand the problem, there is some library mismatch on alpine images. One solutions is using hosts node_modules, but that its is not viable solution when you dont build the project on host but inside of another container running alpine, speaking of some CI/CD stuff etc.

In my case i used version 5.10, which is fine.

stepskop avatar Oct 21 '24 08:10 stepskop

I had the same issue, installing version 5.1.0 fixed it.

mmgroner avatar Nov 03 '24 13:11 mmgroner

if anyone still having this issue, using docker image node:20.10.0 and bcrypt version 5.1.0 fixed the issue

safra36 avatar Dec 11 '24 11:12 safra36

thanks

mgiwa78 avatar Feb 04 '25 20:02 mgiwa78

use bcryptjs library instead of bcrypt

vacaramin avatar Mar 01 '25 13:03 vacaramin

use bcryptjs library instead of bcrypt

perfectly working . thanks so much

eyuelfrew avatar Jun 16 '25 13:06 eyuelfrew