Error building node module in a Vagrant box with NFS

I was trying, and failing, to install node-heapdump:

vagrant@debian7:/vagrant$ npm install heapdump
npm WARN package.json execSync@1.0.1-pre No repository field.
npm http GET https://registry.npmjs.org/heapdump
npm http 304 https://registry.npmjs.org/heapdump

> heapdump@0.2.7 install /vagrant/node_modules/heapdump
> node-gyp rebuild

make: Entering directory `/vagrant/node_modules/heapdump/build'
  CXX(target) Release/obj.target/heapdump/src/heapdump.o
  CXX(target) Release/obj.target/heapdump/src/platform-posix.o
  SOLINK_MODULE(target) Release/obj.target/heapdump.node
flock: ./Release/linker.lock: No locks available
make: *** [Release/obj.target/heapdump.node] Error 71
make: Leaving directory `/vagrant/node_modules/heapdump/build'
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/vagrant/.nvm/v0.10.26/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Linux 3.2.0-4-686-pae
gyp ERR! command "node" "/home/vagrant/.nvm/v0.10.26/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /vagrant/node_modules/heapdump
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v0.12.2
gyp ERR! not ok 
npm ERR! heapdump@0.2.7 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the heapdump@0.2.7 install script.
npm ERR! This is most likely a problem with the heapdump package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls heapdump
npm ERR! There is likely additional logging output above.

npm ERR! System Linux 3.2.0-4-686-pae
npm ERR! command "/home/vagrant/.nvm/v0.10.26/bin/node" "/home/vagrant/.nvm/v0.10.26/bin/npm" "install" "heapdump"
npm ERR! cwd /vagrant
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! code ELIFECYCLE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /vagrant/npm-debug.log
npm ERR! not ok code 0

A github issue suggested that cloning the repo, and running node-gyp rebuild, might give a better error. But that succeeded. Searching for the error message: “flock: ./Release/linker.lock: No locks available”, pointed the finger at the share being mounted using NFS. Unfortunately, after much research and fiddling, the best solution I could come up with was to switch the vagrant share back to a VirtualBox one temporarily.

vagrant@debian7:/vagrant$ npm install heapdump
npm WARN package.json execSync@1.0.1-pre No repository field.
npm http GET https://registry.npmjs.org/heapdump
npm http 304 https://registry.npmjs.org/heapdump

> heapdump@0.2.7 install /vagrant/node_modules/heapdump
> node-gyp rebuild

make: Entering directory `/vagrant/node_modules/heapdump/build'
  CXX(target) Release/obj.target/heapdump/src/heapdump.o
  CXX(target) Release/obj.target/heapdump/src/platform-posix.o
  SOLINK_MODULE(target) Release/obj.target/heapdump.node
  SOLINK_MODULE(target) Release/obj.target/heapdump.node: Finished
  COPY Release/heapdump.node
make: Leaving directory `/vagrant/node_modules/heapdump/build'
heapdump@0.2.7 node_modules/heapdump

Success!

Running Meteor in a Vagrant (virtual)box

If you’re trying to run Meteor in a Vagrant VirtualBox, and getting an error like this when starting the local server:

vagrant@precise32:/vagrant$ meteor 
[[[[[ /vagrant ]]]]]

Unexpected mongo exit code 100. Restarting.
Unexpected mongo exit code 100. Restarting.
Unexpected mongo exit code 100. Restarting.
Can't start mongod

MongoDB had an unspecified uncaught exception.
This can be caused by MongoDB being unable to write to a local database.
Check that you have permissions to write to .meteor/local. MongoDB does
not support filesystems like NFS that do not allow file locking.

As the error message suggests, the problem is caused by the way Vagrant is sharing the src folder with the VM. The easiest solution (suggested here) is to move the Mongo DB data folder to somewhere on the VM, with a symlink in the Meteor folder:

vagrant@precise32:/vagrant/.meteor/local$ ln -s ~/db/                  
vagrant@precise32:/vagrant/.meteor/local$ ls -la
total 12
drwxr-xr-x 1 vagrant vagrant 4096 Jun 17  2013 .
drwxr-xr-x 1 vagrant vagrant 4096 Jun 17 21:47 ..
lrwxrwxrwx 1 vagrant vagrant   17 Jun 17  2013 db -> /home/vagrant/db/

And you should be back in business!

vagrant@precise32:/vagrant$ meteor 
[[[[[ /vagrant ]]]]]

=> Meteor server running on: http://localhost:3000/

UPDATE: this won’t work on a Windows host, apparently; due to the lack of support for symlinks. Sorry!