I have been using Vagrant to configure a nodejs/redis development server. When I setup my application and ran a npm install on the guest machine based on a local package.json file, I’d get weird installation errors such as npm not being able to find node module package.json files. Another error I’d get intermittently is just a hanging install. A sample is included below.
Then, I figured I’d try the same command from the host machine. It worked flawlessly. Then, I remembered that there might be performance problems with Virtual Box’s shared folders. Indeed, this article describes the problem and suggests using nfs.
My share_folder command looks something like this in my Vagrantfile.
1 2 3 | Vagrant::Config.run do |config| config.vm.share_folder "v-www", "/www", "/Users/jamiely/Documents/code/", :nfs => trueend |
Initially, I had problems with this because the path I was sharing was a symbolic link. I didn’t realize this would be a problem and it took some manual experimentation with the NFS setup to determine what the issue was.
Here’s the sample npm output in case it’s helpful to anyone:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | Issue 1: npm install hangsvagrant@oneric32:/www/bgc/bgc-api$ npm installnpm http GET https://registry.npmjs.org/express/2.5.8npm http GET https://registry.npmjs.org/underscore/1.3.3npm http GET https://registry.npmjs.org/jadenpm http GET https://registry.npmjs.org/hiredis/0.1.14npm http GET https://registry.npmjs.org/socket.io/0.8.6npm http GET https://registry.npmjs.org/redis/0.7.2npm http GET https://registry.npmjs.org/socket.io-client/0.8.6HANGINGThis is somewhat resolved by creating the directory from the hostmachine (or before installing)Issue 2: npm cannot access/find files:npm http GET https://registry.npmjs.org/express/2.5.8npm http GET https://registry.npmjs.org/underscore/1.3.3npm http GET https://registry.npmjs.org/jadenpm http GET https://registry.npmjs.org/hiredis/0.1.14npm http GET https://registry.npmjs.org/socket.io/0.8.6npm http GET https://registry.npmjs.org/redis/0.7.2npm http GET https://registry.npmjs.org/socket.io-client/0.8.6npm http GET https://registry.npmjs.org/coffee-script/1.3.1npm ERR! Could not create/www/bgc/bgc-api/node_modules/_<strong>underscore.npmnpm ERR! error installing underscore@1.3.3npm ERR! Could not create/www/bgc/bgc-api/node_modules/</strong>_express.npmnpm ERR! error installing express@2.5.8npm ERR! Could not create/www/bgc/bgc-api/node_modules/_<strong>socket.io.npmnpm ERR! error installing socket.io@0.8.6npm ERR! Could not create/www/bgc/bgc-api/node_modules/</strong>_coffee-script.npmnpm ERR! error installing coffee-script@1.3.1npm ERR! Could not create/www/bgc/bgc-api/node_modules/_<strong>socket.io-client.npmnpm ERR! error installing socket.io-client@0.8.6npm ERR! Could not create/www/bgc/bgc-api/node_modules/</strong>_hiredis.npmnpm ERR! error installing hiredis@0.1.14npm ERR! Could not create/www/bgc/bgc-api/node_modules/_<strong>jade.npmnpm ERR! error installing jade@0.25.0npm ERR! Could not create/www/bgc/bgc-api/node_modules/</strong>_redis.npmnpm ERR! error installing redis@0.7.2npm ERR! Error: UNKNOWN, unknown error'/www/bgc/bgc-api/node_modules'npm ERR! You may report this log at:npm ERR! <//github.com/isaacs/npm/issues>npm ERR! or email it to:npm ERR! <npm-@googlegroups.com>npm ERR!npm ERR! System Linux 3.0.0-12-genericnpm ERR! command "node" "/usr/local/bin/npm" "install"npm ERR! cwd /www/bgc/bgc-apinpm ERR! node -v v0.6.11npm ERR! npm -v 1.1.2npm ERR! path /www/bgc/bgc-api/node_modulesnpm ERR! code UNKNOWNnpm ERR! message UNKNOWN, unknown error'/www/bgc/bgc-api/node_modules'npm ERR! errno {}npm ERR!npm ERR! Additional logging details can be found in:npm ERR! /www/bgc/bgc-api/npm-debug.lognpm not ok |
Thanks for taking the time to write this. I just had the same issue trying to setup node/npm on a vagrant box at work.