Heroku: troubleshooting npm errors during deploy - reading a /tmp file

Some new dependency or some other damn thing is causing npm to error during a get push heroku master deploy:

-----> Node.js app detected
-----> Resolving engine versions
       Using Node.js version: 0.10.1
       Using npm version: 1.2.15
-----> Fetching Node.js binaries
-----> Vendoring node into slug
-----> Installing dependencies with npm
       ....
       npm ERR! Additional logging details can be found in:
       npm ERR!     /tmp/build_24pmtv04ok0ss/npm-debug.log
       npm ERR! not ok code 0

not ok indeed. There's no other useful information printed to the console, so of course I want to see what's in that log file.

So I try a little of this:

$ heroku run cat /tmp/build_24pmtv04ok0ss/npm-debug.log

However, no such file appears to exist:

Running `cat /tmp/build_24pmtv04ok0ss/npm-debug.log` attached to terminal... up, run.3166
cat: /tmp/build_24pmtv04ok0ss/npm-debug.log: No such file or directory

My questions are thus:

  • Where did the log file go? Whyfor can't I read it?
  • Is there any other way for Heroku/npm to give me a verbose error printed to the console?
  • Why does the exact same node environment work fine locally, but fail on Heroku?

When you push code to Heroku, your build is run on a temporary build dyno, so once the build is complete, all the files are gone because dynos have an ephemeral file systems. The reason that heroku run cat /tmp/build_24pmtv04ok0ss/npm-debug.log did not help is that that you attached to a one-off dyno with a fresh file system of your existing app (completely separate from the build dyno).

All hope is not lost. You should be able to see what's going on by tweaking the buildpack to cat out npm-debug.log on exit like this:

function cat_npm_debug_log() {
  if [ -f $BUILD_DIR/npm-debug.log ]; then
    cat $BUILD_DIR/npm-debug.log
  fi
}

trap cat_npm_debug_log EXIT

I haven't thoroughly tested it, but I made a quick fork of the default Node buildpack to do what I just showed above. Feel free to try it out by setting it as a custom buildpack:

heroku config:add BUILDPACK_URL="https://github.com/ryanbrainard/heroku-buildpack-nodejs.git"

Before you go through all the trouble of using a custom build pack, try enabling a more verbose logging output on heroku using:

heroku config:set NPM_CONFIG_LOGLEVEL=verbose

See https://devcenter.heroku.com/articles/troubleshooting-node-deploys for more information.