NPM Link with Vagrant - Symlinks Not Working?

September 5 2013, 2:04pm

NPM Link

It can be handy to use npm link to make npm use a local copy of a node repo if you're working on that other repo at the same time (eg. I'm working on a repo that relies on a npm module I also contribute to). npm link creates a symlink in your npm global modules folder to your local repo, so that npm install/update uses your local copy and doesn't overwrite it.


You used to have to add settings to your config to get symlinks to work in Vagrant (see this issue) but since Vagrant 1.1, Vagrant supports symlinks by default (yay!) (see the commit).

NPM Link Not Working With Vagrant?

If the symlink points to somewhere outside your shared_folder, the symlink won't work though. You have to shared_folder where the symlink points to as well. So just like in the example:

cd ~/projects/node-redis    # go into the package directory
npm link                    # creates global link
cd ~/projects/your-project-repo   # go into some other package directory.
npm link redis              # link-install the package

You have to add to your Vagrant config:

config.vm.synced_folder "/usr/local/lib/node_modules/node-redis", "/usr/local/lib/node_modules/node-redis", :owner => "www-data", :group => "www-data"