heroku/heroku-buildpack-nodejs — Issue #13: Upgrade from Node 0.4 to 0.6 doesn't work when having native packages
Author: lackac
Created: 2012-02-27 16:30:19+00:00
State: open

We have run into an issue today on Heroku trying to upgrade our Node version. The problem was caused by having `hiredis` in our dependencies which the buildpack couldn't rebuild correctly. The build itself run without errors but we have seen a lot of errors in the logs:

```
2012-02-27T15:09:27+00:00 app[web.1]: FATAL ERROR: v8::HandleScope::Close() Local scope has already been closed
```

Looking into the issue I have found that it must have been caused by having the old node version in the path. I'm not sure about this but I suspect that it must have come from the slug cache.

Trying to solve the issue I removed all the native packages from our `package.json`. This didn't help as another strange thing happened: all the packages that had been removed were still being installed when deploying.

I think this is caused by the buildpack messing up cache directories. I looked into the `compile` script and found [this](https://github.com/heroku/heroku-buildpack-nodejs/blob/master/bin/compile#L21):

``` sh
CACHE_STORE_DIR="$CACHE_DIR/node_modules/$NPM_VERSION"
CACHE_TARGET_DIR="$BUILD_DIR/node_modules"
```

Here you're using `$NPM_VERSION` without first finding the right value with `package_resolve_version`. I don't know what the default value is for this variable but I suspect that it's either undefined or a fixed `1.0.94`. Either way the buildpack copies old packages over to the new build even when the app is trying to use another npm version.

We temporarily solved the issue in our case by enabling the *user_env_compile* labs plugin and setting `NPM_VERSION` (and `NODE_VERSION` just to be safe) explicitely. With that the build process started with a clean `node_modules` dir and everything (even native packages) worked perfectly.