Node.js deployment fails with callback never executed error

I’m trying to deploy my Node.js application to a cloud hosting platform and keep running into this frustrating issue. When I push my code using git, the deployment process starts normally but then crashes during the npm install phase.

Here’s what happens during the build:

-----> Node.js app detected
-----> Installing dependencies with npm
       npm http GET https://registry.npmjs.org/express
       npm http GET https://registry.npmjs.org/mongoose
       npm http 200 https://registry.npmjs.org/express
       npm http 200 https://registry.npmjs.org/mongoose
       
       > [email protected] install /tmp/build_xyz123/node_modules/bcrypt
       > node-gyp rebuild
       
       make: Entering directory `/tmp/build_xyz123/node_modules/bcrypt/build`
         CXX(target) Release/obj.target/bcrypt_lib.o
         SOLINK_MODULE(target) Release/obj.target/bcrypt_lib.node
       make: Leaving directory `/tmp/build_xyz123/node_modules/bcrypt/build`
       
       npm ERR! cb() never called!
       npm ERR! not ok code undefined
       npm ERR! cb() never called!
       npm ERR! not ok code 1
 !     Failed to install dependencies with npm
 !     Push rejected, failed to compile Node.js app

The build was working perfectly fine until a few days ago. Now every deployment attempt ends with the same callback error. Has anyone encountered this specific npm callback issue during cloud deployments? What could be causing npm to fail like this during the dependency installation process?

This error typically occurs when there’s insufficient memory or disk space during native module compilation. The bcrypt module requires significant resources to build and if the build environment runs out of memory, npm callbacks get stuck indefinitely. I experienced this exact issue when my hosting provider had memory limits that were too restrictive for native module builds. Try switching to bcryptjs instead of bcrypt as a temporary workaround since it’s pure JavaScript and doesn’t require compilation. You can also check if your hosting platform allows you to increase build memory limits or use a different buildpack. Another approach is to commit your node_modules folder or use npm ci instead of npm install during deployment, though this increases repository size significantly.

sounds like npm cache corruption issue. try clearing cache locally with npm cache clean --force then redeploy. also check if your package.json got any weird changes recently that might be causeing this callback bug

I had a very similar deployment failure last month with the exact same callback error message. In my case it turned out to be a version mismatch between the Node.js version running locally versus what the hosting platform was using. The bcrypt module compilation was failing silently and causing npm to hang indefinitely. Check your package.json engines field and make sure it specifies the Node version your hosting platform supports. Also try updating your npm version in package.json engines since older npm versions had known callback bugs during native module compilation. Once I locked down both Node and npm versions to match the deployment environment exactly, the callback never executed error disappeared completely.