javascriptnode.jsbcrypt

bcrypt genSalt never returns


I'm trying to use genSalt from the bcrypt package method but it run forever.

I tried to set the rounds value to 1 and also to use the sync version of the method but it never returns.

console.log("A");
const salt = await bcrypt.genSalt(1);
console.log("B");
const pwd_hash = await bcrypt.hash(password, salt);
console.log("C");

The console only display "A".

I'm using nestjs and my app is running is a docker container. The problem doesn't occurs when the app is runned outside the docker container.


Solution

  • Problem solved by @JaredSmith in the comments of OP (sept. 2023).

    @JaredSmith:

    are you installing node dependencies directly in the docker container or on something else and then copying them over? Because the bcrypt package uses node-gyp to run C++ code and that's architecture-dependent: if you compile for say, Apple silicon and then try to run that code in a x64 docker image you'll get a segfault which could explain your problem. ...if you are copying over the node_modules folder, either directly or as part of your project directory, try stripping them out and running npm i (or yarn or whatever you're using) in the container instead.

    @tguichaoua:

    That's it! I was using the node_module from the host system.