Symlink shenanigans – node.js, npm, express and vagrant 7

Vagrant, node and npm

Recently I was working on a new project on a virtual box set up through vagrant. For those of you who haven’t used it, vagrant is an amazing tool that makes it crazy-easy to set up and deploy uniform development environments on virtual servers. However, I ran in to a very frustrating issue when trying to install the node.js framework express through npm.


Node was set up and running fine, and I’d successfully gotten a few modules working by adding them to the dependencis list in package.json and running npm install. I then added express, so my dependencies list now looked like:

1
2
3
4
5
 "dependencies": {
    "aws-sdk": "0.9.x",
    "express": "3.x",
    "pg": "x"
  }

I ran npm install, then got hit with an error along the lines of:

1
2
error code EROFS
error errno 56

This error means the file system is read only. But I already managed to install two other modules in the same way on the same system! So what gives?

Symlink shenanigans

The issue is caused by the way express attempts to symlink binaries. One of the restrictions when using virtualbox is that symlinks can’t be created within shared folders. (My code was mounted from a shared folder on my local machine) This is discussed in a bit more detail on this github issue.

There are a wide variety of suggested fixes for this floating around on the net. One is to edit the vagrant config file to allow symlinks to be created, explained in more detail here. This one didn’t work for me, so my search went on, and eventually led me to the github issue linked above.

The issue resulted in a patch being added to npm which will install packages without forcing the symlinks. So, when running “npm install” on a virtual machine created through vagrant, run it as:

1
npm install --no-bin-link

This will install the dependencies listed in the packages.json file, whilst preventing npm from creating symlinks for any binaries the packages may contain.

7 thoughts on “Symlink shenanigans – node.js, npm, express and vagrant

  1. Reply tfitch Jun 4,2013 6:24 pm

    Thank you – this

    1
    --no-bin-link flag

    was exactly the solution to a problem I’ve been having with my Vagrant VM.

  2. Reply floodedcodeboy Jul 25,2013 10:45 pm

    amazing. had such issues with this. thanks!

  3. Reply Steve Aug 7,2013 11:19 pm

    Dude!! Thanks for this. I thought I’d never find the answer.

  4. Reply maxcnunes Sep 20,2013 10:54 pm

    Thanks, really helpful!

  5. Pingback: Vagrant – Error: UNKNOWN, symlink | maxcnunes

  6. Reply TJ Dec 22,2015 3:20 am

    Over 2 years later and this is still relevant.

    Thanks

  7. Reply Sanic.exe Oct 30,2018 5:24 pm

    Over a thousand years later and this is still rele-fucking-vant.

Leave a Reply