Nodejs Bcrypt + Heroku fail deploy

i am having problems when i try to do a deployment in heroku. The funny part is this was working three days ago. Also, is working fine in local machine.

The version of Bcrypt is 3.0.0, node 8.12.0

I really need to deploy this server. Could you please show me how to fix this error? I have tried some solutions I found but nothing worked. I even tried to uninstall and install again Bcrypt but does not work.

Thanks for the help.

This is the log.

-----> Node.js app detected

-----> Creating runtime environment

       NPM_CONFIG_LOGLEVEL=error
       NODE_VERBOSE=false
       NODE_ENV=production
       NODE_MODULES_CACHE=true

-----> Installing binaries
       engines.node (package.json):  unspecified
       engines.npm (package.json):   unspecified (use default)

       Resolving node version 8.x...
       Downloading and installing node 8.12.0...
       Using default npm version: 6.4.1

-----> Restoring cache
       - node_modules

-----> Building dependencies
       Installing node modules (package.json + package-lock)

       > [email protected] install /tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt
       > node-pre-gyp install --fallback-to-build

       make: Entering directory '/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/build'
       make: Entering directory '/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/build'
       CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
       CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o
       rm: cannot remove './Release/.deps/Release/obj.target/bcrypt_lib/src/blowfish.o.d.raw': No such file or directory
       bcrypt_lib.target.mk:103: recipe for target 'Release/obj.target/bcrypt_lib/src/blowfish.o' failed
       make: *** [Release/obj.target/bcrypt_lib/src/blowfish.o] Error 1
       make: Leaving directory '/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/build'
       CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o
       gyp ERR! build error
       gyp ERR! stack Error: `make` failed with exit code: 2
       gyp ERR! stack     at ChildProcess.onExit (/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
       gyp ERR! stack     at emitTwo (events.js:126:13)
       gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
       gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
       gyp ERR! System Linux 4.4.0-1027-aws
       gyp ERR! command "/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/bin/node" "/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/lib/binding" "--napi_version=3" "--node_abi_napi=napi"
       gyp ERR! cwd /tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt
       gyp ERR! node -v v8.12.0
       gyp ERR! node-gyp -v v3.8.0
       gyp ERR! not ok
       node-pre-gyp ERR! build error
       node-pre-gyp ERR! stack Error: Failed to execute '/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/bin/node /tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi' (1)
       node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
       node-pre-gyp ERR! stack     at emitTwo (events.js:126:13)
       node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
       node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:915:16)
       node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
       node-pre-gyp ERR! System Linux 4.4.0-1027-aws
       node-pre-gyp ERR! command "/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/bin/node" "/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
       node-pre-gyp ERR! cwd /tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt
       node-pre-gyp ERR! node -v v8.12.0
       node-pre-gyp ERR! node-pre-gyp -v v0.10.2
       node-pre-gyp ERR! not ok
       Failed to execute '/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/bin/node /tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi' (1)
       ../src/bcrypt.cc:316:1: fatal error: opening dependency file ./Release/.deps/Release/obj.target/bcrypt_lib/src/bcrypt.o.d.raw: No such file or directory
       compilation terminated.
       bcrypt_lib.target.mk:103: recipe for target 'Release/obj.target/bcrypt_lib/src/bcrypt.o' failed
       make: *** [Release/obj.target/bcrypt_lib/src/bcrypt.o] Error 1
       make: Leaving directory '/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/build'
       gyp ERR! build error
       gyp ERR! stack Error: `make` failed with exit code: 2
       gyp ERR! stack     at ChildProcess.onExit (/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
       gyp ERR! stack     at emitTwo (events.js:126:13)
       gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
       gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
       gyp ERR! System Linux 4.4.0-1027-aws
       gyp ERR! command "/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/bin/node" "/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/.heroku/node/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt/lib/binding" "--napi_version=3" "--node_abi_napi=napi"
       gyp ERR! cwd /tmp/build_7bec2ec99162a9fbf0c48b54d7fcf7ea/node_modules/bcrypt
       gyp ERR! node -v v8.12.0
       gyp ERR! node-gyp -v v3.8.0
       gyp ERR! not ok
       npm ERR! code ELIFECYCLE
       npm ERR! errno 1
       npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
       npm ERR! Exit status 1
       npm ERR!
       npm ERR! Failed at the [email protected] install script.
       npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

       npm ERR! A complete log of this run can be found in:
       npm ERR!     /tmp/npmcache.FCizS/_logs/2018-09-12T04_21_02_165Z-debug.log
-----> Build failed

       We're sorry this build is failing! You can troubleshoot common issues here:
       https://devcenter.heroku.com/articles/troubleshooting-node-deploys

       Some possible problems:

       - Node version not specified in package.json
       https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version

       Love,
       Heroku

 !     Push rejected, failed to compile Node.js app.
 !     Push failed

Answers

Well I tried the solution by @GMachado and it did not work for me.

I know this happens because bcrypt requires a native compiler. I used python to compile bcrypt on my local machine but i am not willing to go through this stress when deploying on heroku

As a quick solution, I unistalled bcrypt then installed bcryptjs, bcryptjs is the pure-javascript version of bcrypt. Just think of it as a light version of bcrypt. While bcrypt requires native compiler to compile, bcryptjs does not. bcrypt is about 1.3 times faster than bcryptjs. thats the major difference.

First uninstall bcrypt by typing in the command:

npm uninstall --save bcrypt

Then install bcryptjs by typing in the command

npm install --save bcryptjs

Afterwards, Navigate to where you have imported bcrypt on your app and change it to

require("bcryptjs")

the rest of the application should remain the same.

Go back to deploy on heroku and you should be fine.

Posted on by Anonymous

I got same behaviour for node 8.12 in travis ci since last days.

Looks like nodejs release new nodejs version 8.12 few days ago and bcrypt don't have prebuild for that version, but their script for build from source fails on linux.

Also for nodejs 8 recommended to use bcrypt 1.0.3 according their version compatibility.

Check github issue for more details: https://github.com/kelektiv/node.bcrypt.js/issues/648

Posted on by Anonymous

Had the same thing happening to me.

Node version not specified in package.json

Try and do what heroku suggest, define the node version you are using on the package.json.

Get the version you are using for development:

node --version

Then put it on package.json:

{ "name": "myapp", 
  "description": "a really cool app",  
  "version": "1.0.0", 
  "engines": { 
      "node": "8.9.4" 
   }
}


Posted on by GMachado