The bcrypt bug on Docker
I recently faced on bug while using the NodeJs encryption library; bcrypt on Docker.
internal/modules/cjs/loader.js:807
app_1 | return process.dlopen(module, path.toNamespacedPath(filename));
Above is the bug I faced.
Backstory
I was working on a NodeJs project and I had set up Docker; if you do not know what Docker is, check it out here.
I configured the NodeJs app service in my docker-compose.yml
file to use the local node_modules folder, basically: I was using the same node_modules on local development and on Docker on my laptop.
The advantage is that npm install
would not have to reinstall all the dependencies when I run docker-compose up
.
The bug
I was using bcrypt to hash some data, my app worked locally but when I ran docker-compose up
it gave the error above, after many ups and downs, I figured that the bcrypt node modules are different for macOS and Linux OS, and other OS.
I use a MacBook Pro with macOS Mojave but the Docker image was Linux.
The fix
I had a start.sh
file before, so I added two new lines:
npm uninstall bcrypt
would remove bcrypt modules for the other operating system.npm install bcrypt
would install for the current machine that the app would be running on.
Works like magic!
The purpose of writing this is for anyone who encounters this bug in the future, I hope I was able to help.