Home » Nodejs » What permissions do I need to install Bower on Vagrant on Windows?

What permissions do I need to install Bower on Vagrant on Windows?

Posted by: admin November 29, 2017 Leave a comment

Questions:

I kept running into this error when installing Bower through NPM on a Windows 7 machine running a precise32 Ubuntu Box on Vagrant. I tried every combination of commands and always got the same or very similar errors

Installing locally, globally, with sudo, without sudo, etc.

...
npm ERR! Error: EPERM, open '/home/vagrant/tmp/npm-1214-AHbOCwuM/1391873680685-0.36021817452274263/package/build/node_modules/cheerio/node_modules/htmlparser2/node_modules/readable-stream/test/simple/test-stream2-readable-empty-buffer-no-eof.js'
npm ERR!  { [Error: EPERM, open '/home/vagrant/tmp/npm-1214-AHbOCwuM/1391873680685-0.36021817452274263/package/build/node_modules/cheerio/node_modules/htmlparser2/node_modules/readable-stream/test/simple/test-stream2-readable-empty-buffer-no-eof.js']
npm ERR!   errno: 50,
npm ERR!   code: 'EPERM',
npm ERR!   path: '/home/vagrant/tmp/npm-1214-AHbOCwuM/1391873680685-0.36021817452274263/package/build/node_modules/cheerio/node_modules/htmlparser2/node_modules/readable-stream/test/simple/test-stream2-readable-empty-buffer-no-eof.js' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.2.0-23-generic-pae
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "bower" "--no-bin-links"
npm ERR! cwd /home/vagrant
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.24
npm ERR! path /home/vagrant/tmp/npm-1214-AHbOCwuM/1391873680685-0.36021817452274263/package/build/node_modules/cheerio/node_modules/htmlparser2/node_modules/readable-stream/test/simple/test-stream2-readable-empty-buffer-no-eof.js
npm ERR! code EPERM
npm ERR! errno 50
npm ERR! stack Error: EPERM, open '/home/vagrant/tmp/npm-1214-AHbOCwuM/1391873680685-0.36021817452274263/package/build/node_modules/cheerio/node_modules/htmlparser2/node_modules/readable-stream/test/simple/test-stream2-readable-empty-buffer-no-eof.js'
...

EDIT: As well as my answer below please note the file directory + file size limitation when using Windows (260 characters I believe)

I have had to install vagrant in a folder directly on my c:/ drive to get over this limitation as some packages end up having nested dependencies causing this limit to be exceeded. My problem was with grunt-contrib-less

Answers:

Self answering as I couldn’t find a solution anywhere else on StackOverflow

I eventually got it to work via changing to the root user via su root and trying to install globally again. Apparently just using sudo wasn’t enough.

So it became

[email protected]: npm install -g bower --no-bin-links

EDIT: As well as this solution please note the file directory + file size limitation when using Windows (260 characters I believe)

I have had to init a vagrant instance in a folder directly on my c:/ drive to get over this limitation as some packages end up having nested dependencies causing this limit to be exceeded. My problem was with grunt-contrib-less

EDIT 2: After coming across this problem again and again I’ll add a bit more information for people here regarding node modules and vagrant under Windows.

I now overcome the file path limitation via putting any long dependency chains that fail due to path length (usually EPERM) I add one of the packages in the chain to my own package.json. This means the long requirement chain is split as npm does not re-install the package deeper in the tree if it’s already installed.

Just make sure you require a version which is valid for the version string for the module.

The order of the dependencies in package.json does not matter, dependencies are resolved before anything is installed

Questions:
Answers:

One of ops guys (vagrant and node.js quick tip) found a solution for that problem. Basically you need to have the following code in your Vagrant file:

config.vm.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]

That will allow npm to create symlinks for the modules that require it.
Than install packages without forcing the symlinks. So, when running npm install on a virtual machine created through vagrant, run it as:

sudo npm install --no-bin-link

It was usefull for me when I installed the express
module.

Questions:
Answers:

With Vagrant 1.5 on Windows, you can now use rsync or smb folder shares which won’t have this problem.

Questions:
Answers:

To get around the 260 character file length limit in windows, which npm seems to surpass quite easily, you can use the npm link command.

This will allow you to use node_modules local to your project. If you run it on your guest machine it will install them globally on your guest machine and then create a symlink in your projects node_modules folder. That way only the symlink is shared to the windows host machine and the 260 file length limit is not exceeded.

I go over this in more detail in this blog post here.