nvm installed node and npm, symlink issue when installing local browserify - node.js

Today I have installed the latest version of node through nvm on Linux Mint (Ubuntu 13.10).
Thanks to nvm, I now don't have to use the sudo command with npm - which has solved problems with a few packages.
$ node -v
v0.10.29
$ npm -v
1.4.14
However when entering this command:
npm install browserify --save-dev
I now get the following error:
npm ERR! Error: EACCES, symlink '../browserify/bin/cmd.js'
npm ERR! { [Error: EACCES, symlink '../browserify/bin/cmd.js'] errno: 3, code: 'EACCES', path: '../browserify/bin/cmd.js' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.11.0-12-generic
npm ERR! command "/home/dave/.nvm/v0.10.29/bin/node" "/home/dave/.nvm/v0.10.29/bin/npm" "install" "browserify" "--save-dev"
npm ERR! cwd /var/www/100mondays-l4.2/frontend
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! path ../browserify/bin/cmd.js
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, symlink '../browserify/bin/cmd.js'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /var/www/100mondays-l4.2/frontend/npm-debug.log
npm ERR! not ok code 0
When I try to comply with the error advice:
$ sudo npm install browserify --save-dev
sudo: npm: command not found
I have been able to install other modules with npm - globally and locally - with no issues. So my guess is the error is to do with symlinks? My local site is in /var/www/ but my node/npm installation is in ~/.nvm/, and my home folder doesn't follow symlinks? However I'm not a server/Linux expert so could be off the mark.
This works fine:
npm install browserify -g
Any help greatly received.

Adding browserify to my package.json manually and using npm install from the project root solved my issue. Not really sure why.

Related

Cannot npm install 'mean-cli' module on Mac OS X

UPDATE:
Apparently, it is bad practice to use sudo to install node modules. Instead, changing folder permissions will solve this issue.
See the answer here: https://stackoverflow.com/a/31546496/2859315
ORIGINAL POST:
Currently, I have installed Node (version v0.12.7) and NPM. I am trying to install the mean-cli package from NPM.
I am following the installation instructions found here: https://github.com/linnovate/mean#installation
Also, I was taking a MEAN Stack development course on Udemy. Here is the lecture:
https://www.udemy.com/mean-stack-for-beginners/#/lecture/2697540
So far, I have installed both prerequisite packages, Gulp and Bower:
$ npm install -g gulp
// and bower
$ npm install -g bower
Firstly, I tried installing by using npm install -g mean-cli but that threw permission errors without using sudo. Then, even using sudo would not work.
Secondly, I tried updating and reinstalling node and NPM. Still have the same issue.
When I type the command sudo npm install -g mean-cli,
I get this response:
> mean-cli#0.10.14 preinstall /usr/local/lib/node_modules/mean-cli
> node ./scripts/preinstall
shell-init: error retrieving current directory: getcwd: cannot access parent directories: Permission denied
node.js:720
var cwd = process.cwd();
^
Error: EACCES, permission denied
at Error (native)
at Function.startup.resolveArgv0 (node.js:720:23)
at startup (node.js:63:13)
at node.js:814:3
npm ERR! Darwin 14.4.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "mean-cli"
npm ERR! node v0.12.7
npm ERR! npm v2.11.3
npm ERR! code ELIFECYCLE
npm ERR! mean-cli#0.10.14 preinstall: `node ./scripts/preinstall`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the mean-cli#0.10.14 preinstall script 'node ./scripts/preinstall'.
npm ERR! This is most likely a problem with the mean-cli package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./scripts/preinstall
npm ERR! You can get their info via:
npm ERR! npm owner ls mean-cli
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Library/WebServer/Documents/NodeJS/mean/npm-debug.log
It seems like the problem lies here: Failed at the mean-cli#0.10.14 preinstall script 'node, but I am not sure about how to debug this further.
Any insight or helpful information is appreciated! Thanks!
Apparently, it is bad practice to use sudo to install node modules. Instead, changing folder permissions will solve this issue.
See the answer here: https://stackoverflow.com/a/31546496/2859315
To reclaim ownership of the /usr/local use the command below
Sudo chown –r $USER /usr/local

Error installing Gulp

I am pretty new to using terminal and installing gulp, but I am running through a few errors. Errors keep popping up and I am not sure why. My goal for right now is to install gulp globally, but not sure if any old files are interfering. Maybe a clean out and reinstall would work? Error is below. Thanks!
pm ERR! tar.unpack untar error /Users/.npm/gulp/3.9.0/package.tgz
npm ERR! Darwin 14.1.0
npm ERR! argv "node" "/usr/local/bin/npm" "install" "-g" "gulp"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! path /usr/local/lib/node_modules/gulp
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/gulp'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/gulp']
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/gulp',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/gulp',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53',
npm ERR! 'FSReqWrap.oncomplete (fs.js:95:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /usr/local/bin/npm-debug.log
Other answers are bypassing these issues by the use of sudo or su root. I personally don't recommend this. The reason it works is because on OSX the global npm module directory has stricter permissions. Running your commands with root privileges just to get around permissions issues is likely only going to cause you headaches down the road and open you up to security vulnerabilities. At the very least it's going to cause you to have to use sudo constantly when trying to do routine node/npm things. The safer way would be to change the permissions of just that directory. However, even that can sometimes cause nightmares.
My alternative recommendation to the other suggestions here is to use nvm.
You can install it with curl (you have this already, just paste the below command):
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
Or you can use Homebrew if you have that installed:
brew install nvm
Once installed, you'll be able to easily install any node or iojs version that you want.
nvm install node
The above command will install the latest version of node. The nice part is that all your node/iojs installations are managed within ~/.nvm/, meaning they are inside your home directory where you'll always have full access permissions and won't ever need to use sudo.
You dont have the rights to write un /sur/local
Either you run sudo npm install -g gulp or give your user the rights to write in /usr/local

Failing to install the Grunt command line interface

I am currently having trouble installing the grunt command line interface, i get a whole lot of errors on the log when I try and install it using instructions off a tutorial website. I just added node.js from a package I downloaded off their website. Any help would be appreciated?
I used the following command as detailed on the roots WordPress instructions page
npm install -g grunt-cli
and this error message was returned
npm ERR! Error: Attempt to unlock grunt-cli, which hasn't been locked
npm ERR! at unlock (/usr/local/lib/node_modules/npm/lib/utils/locker.js:44:11)
npm ERR! at cb (/usr/local/lib/node_modules/npm/lib/cache/add-local.js:30:5)
npm ERR! at /usr/local/lib/node_modules/npm/lib/cache/add-local.js:47:20
npm ERR! at /usr/local/lib/node_modules/npm/lib/utils/locker.js:30:7
npm ERR! at /usr/local/lib/node_modules/npm/node_modules/lockfile/lockfile.js:167:38
npm ERR! at OpenReq.Req.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:144:5)
npm ERR! at OpenReq.done (/usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:64:22)
npm ERR! at Object.oncomplete (fs.js:107:15)
npm ERR! If you need help, you may report this entire log,
npm ERR! including the npm and node versions, at:
npm ERR! http://github.com/npm/npm/issues
npm ERR! System Darwin 13.2.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /Users/jonbeech
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/jonbeech/npm-debug.log
npm ERR! not ok code 0
➜ ~
Run sudo npm install -g grunt-cli you need sudo privileges when installing something globally, or remove the -g switch.
Try to avoid needing sudo with npm, there are likely going to be other permissions errors. Here is what I did after installing npm with sudo:
Uninstall NPM: sudo npm uninstall npm -g
Install NVM so that I can install npm without needing sudo (similar to RVM), see: https://github.com/creationix/nvm#installation
Install latest npm: nvm install stable
Clear caches npm cache clear
and then everything worked

Why can't i npm install nodemon or supervisor on OSX 10.8.4?

I'm just trying to install nodemon or supervisor using terminal, and I keep getting this error which I don't understand. I tried running as the administrator with sudo npm install supervisor -g which seemed to work, but than didn't when i deleted/added some js code. Any ideas?
Squirrels-MacBook-Air:lesson7_examples Squirrel$ npm install nodemon -g
npm http GET https://registry.npmjs.org/nodemon
npm http 304 https://registry.npmjs.org/nodemon
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/nodemon',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/nodemon',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.4.1
npm ERR! command "node" "/usr/local/bin/npm" "install" "nodemon" "-g"
npm ERR! cwd /Users/Squirrel/Documents/Code/Memry/Memry_Mongoose
npm ERR! node -v v0.10.21
npm ERR! npm -v 1.3.11
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! fstream_path /usr/local/lib/node_modules/nodemon
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/nodemon'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/Squirrel/Documents/Code/Memry/Memry_Mongoose/npm-debug.log
npm ERR! not ok code 0
Squirrels-MacBook-Air:lesson7_examples Squirrel$
P.S. I'm running this on a pre-existing template and my dependencies are
"dependencies": {
"mongoose": "~3.6.15",
"express": "~3.3.4",
"jade": "~0.34.1",
"email-validator": "~0.1.2"
}
When I tried sudo this is what happened:
sudo npm install supervisor -g --save
Password:
npm http GET https://registry.npmjs.org/supervisor
npm http 304 https://registry.npmjs.org/supervisor
/usr/local/bin/node-supervisor -> /usr/local/lib/node_modules/supervisor/lib/cli-wrapper.js
/usr/local/bin/supervisor -> /usr/local/lib/node_modules/supervisor/lib/cli-wrapper.js
supervisor#0.5.6 /usr/local/lib/node_modules/supervisor
Which seemed to work. But than in the application code I began to add and delete javascript and click save, yet the effects wouldn't take place unless I restarted the server within terminal.
Late to the party, but it is important to note that you should avoid using sudo when npm installing. It is a huge security risk to sudo npm install as you are giving arbitrary scripts root access to your machine.
Instead you should make yourself the owner of the directories in which the NPM
sudo chown -R $USER /usr/local
and then
sudo chown -R $USER ~/.npm
Now you should be able to run the commands without sudo:
npm install supervisor -g --save
You're encountering an EACCES error, which means you don't have the rights to create a directory in /usr/local/lib/node_modules/nodemon as a standard user in Mac OS X.
There are two solutions:
Run the same command as a superuser, using sudo. The package will be installed in /usr/local/lib/node_modules.
Change npm's settings to install all of your global packages into one of your private folders, that your user has ownership of. See this relevant answer that explains step-by-step the process.
I know I'm late to the question, but you should check out nvm (node's answer to rbenv or virtualenv).
Install:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
Then add . ~/.nvm/nvm.sh to your ~/.bashrc, ~/.profile, or ~/.zshrc
Usage:
If you wanted to use version 0.10, run nvm install 0.12.7 (or nvm install stable), then nvm use 0.12.7.
Install your libs, EACCESS error-free, and go to town. npm install -g supervisor works just fine!
To load a specific version default in new tabs, use the command nvm alias default 0.12.7

Trouble installing topojson on ubuntu

I've been trying to install topojson by following Mike Bostock's Let's Make a Map tutorial http://bost.ocks.org/mike/map/ and I believe I have managed to get the most recent version of Node.js and npm. $which ogr2ogr works as well. I'm quite new to programming and Ubuntu and would sincerely appreciate some thorough help as to why npm install topojson -g yields the following errors. When I try the same command with sudo it yields errors like: npm ERR! registry error parsing json and gyp ERR! stack Error: "pre" versions of node cannot be installed, use the --nodedir flag instead
Thanks!
npm ERR! Error: EACCES, open '/home/natecraft/.npm/7edf76d6-topojson.lock'
npm ERR! { [Error: EACCES, open '/home/natecraft/.npm/7edf76d6-topojson.lock']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/natecraft/.npm/7edf76d6-topojson.lock' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Linux 3.5.0-23-generic
npm ERR! command "/home/natecraft/.nvm/v0.10.15/bin/node" "/home/natecraft/.nvm/v0.10.15/bin/npm" "install" "topojson" "-g"
npm ERR! cwd /home/natecraft/Downloads/node-latest-install
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.3.5
npm ERR! path /home/natecraft/.npm/7edf76d6-topojson.lock
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, open '/home/natecraft/.npm/7edf76d6-topojson.lock'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/natecraft/Downloads/node-latest-install/npm-debug.log
npm ERR! not ok code 0
First, please check your version of node.js -- use the stable version, not the devel version. Second, invoke the npm command as superuser.
$ sudo npm install -g topojson
So far, when I switch my node.js into stable version, TopoJSON installation is running well. Thank you for your attention.
I came across this error when installing topojson (Debian 3.2.0-4-amd64). My steps to get things working (also discussed here).
Install node v 0.11.10
git clone https://github.com/joyent/node.git
cd node
git checkout v0.11.10
./configure && make
sudo make install
Remove debian gyp and install via npm:
sudo apt-get remove gyp
npm install -g gyp
Explicitly install contextify, although that was the version already installed.
npm install contextify#0.1.7
then, installing topojson should work
sudo npm install -g topojson

Resources