How can I install the grunt-cli without getting errors? - node.js

Inspired by Chris Coyier's post, I decided I'd give grunt a go. But I'm having big problems getting set up.
First, I installed Node.
Then I added a package.json file to my project root, including this:
{
"name": "example-project",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1"
}
}
Then I ran npm install
Finally, I ran npm install -g grunt-cli
which came back with a ton of errors:
npm http GET https://registry.npmjs.org/grunt-cli
npm http 304 https://registry.npmjs.org/grunt-cli
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/grunt-cli',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/grunt-cli',
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 11.4.2
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /Users/bryce/repo
npm ERR! node -v v0.10.23
npm ERR! npm -v 1.3.17
npm ERR! path /usr/local/lib/node_modules/grunt-cli
npm ERR! fstream_path /usr/local/lib/node_modules/grunt-cli
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/grunt-cli'
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/bryce/repo/npm-debug.log
npm ERR! not ok code 0
Bryce:repo bryce$ npm install -g grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http 304 https://registry.npmjs.org/grunt-cli
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/grunt-cli']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/grunt-cli',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/grunt-cli',
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 11.4.2
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /Users/bryce/repo
npm ERR! node -v v0.10.23
npm ERR! npm -v 1.3.17
npm ERR! path /usr/local/lib/node_modules/grunt-cli
npm ERR! fstream_path /usr/local/lib/node_modules/grunt-cli
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/grunt-cli'
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/bryce/repo/npm-debug.log
npm ERR! not ok code 0
I assume the above errors are the reason that when I tried to run grunt, I simply get -bash: grunt: command not found
Anyone out there know what's happening?

All it took was adding 'sudo', since I didn't have permission to install the grunt-cli by default. Once I ran the following command and entered my password, it worked as expected.
sudo npm install -g grunt-cli
Hope this helps someone!

EDIT:
The article quoted below is quite old and refers to pre-v0.3 Yikes! Currently, if npm is run with sudo rights it will downgrade to the nobody user before executing commands.
According to the maintainer of npm, installing packages with sudo is considered bad practice because you are allowing that package to have complete control of your system and you can't and SHOULDN'T trust these packages with root access.
http://howtonode.org/introduction-to-npm

Since you should not install using sudo - you will do this before installing packages and no longer will hit permission errors:
sudo chown -R $USER /usr/local
source: https://howtonode.org/introduction-to-npm

I would recommend installing grunt within your project (instead of using the -g option).
For example, to install the Grunt command line tools use:
cd ~/path-to-my-project
npm install grunt-cli --save-dev
If you want to run grunt then you use:
cd ~/path-to-my-project
./node_modules/./bin/grunt
By installing grunt-cli within your project, you'll have full control over which version gets installed and you don't have to rely on inconsistent PATH variables.

I was having this issue as well, and after reading through the output a little closer i realized that my installed version of node.js was not compatible with the current version of grunt-cli.
Updated node.js problem solved.

Related

npm install ember-cli fails on ubuntu trusty in vagrant virtualbox

I have not been able to successfully install ember-cli. I finally was able to run:
sudo npm install -g ember-cli
But when running:
user#host:~ ember new ember-app
I get:
/usr/bin/env: node: No such file or directory
I installed node.js from the repositories using sudo apt-get install nodejs and same with npm.
I have installed bower and tried to re-install npm. Here is the last error:
user#host:~ npm install -g ember-cli
npm http GET https://registry.npmjs.org/ember-cli
npm http 200 https://registry.npmjs.org/ember-cli
npm http GET https://registry.npmjs.org/ember-cli/-/ember-cli-0.2.7.tgz
npm http 200 https://registry.npmjs.org/ember-cli/-/ember-cli-0.2.7.tgz
npm ERR! Error: shasum check failed for /home/user/tmp/npm-14461-xfhNCJKF/1435776262780-0.6301117099355906/tmp.tgz
npm ERR! Expected: fefcd9fe7faf276a5a68c8bfcc92288c0f0678d5
npm ERR! Actual: c120ca4196f11da6e51f9c8ebb273439dcfee615
npm ERR! at /usr/lib/nodejs/sha/index.js:38:8
npm ERR! at ReadStream.<anonymous> (/usr/lib/nodejs/sha/index.js:85:7)
npm ERR! at ReadStream.EventEmitter.emit (events.js:117:20)
npm ERR! at _stream_readable.js:920:16
npm ERR! at process._tickCallback (node.js:415:13)
npm ERR! If you need help, you may report this log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR! System Linux 3.13.0-55-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "-g" "ember-cli"
npm ERR! cwd /home/user
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /home/user/npm-debug.log
npm ERR! not ok code 0
For clarity, I am able to install other items using npm. Just not ember-cli.
UPDATE:
I am getting similar errors that I've received in previous executions of npm install -g ember-cli when run the following:
npm install -g latest-version
Received the following error:
npm http GET https://registry.npmjs.org/latest-version
npm http 304 https://registry.npmjs.org/latest-version
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/latest-version'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/latest-version']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/latest-version',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/latest-version',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/lib/nodejs/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/lib/nodejs/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 Linux 3.13.0-55-generic
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "--global" "latest-version"
npm ERR! cwd /home/user
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR! path /usr/local/lib/node_modules/latest-version
npm ERR! fstream_path /usr/local/lib/node_modules/latest-version
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/latest-version'
npm ERR! fstream_stack /usr/lib/nodejs/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/lib/nodejs/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! /home/user/npm-debug.log
npm ERR! not ok code 0
-
UPDATE:
"Fix" is in the comment below.
For your node issue, try the following command which will make it so your system recognizes your node.js directory as node:
sudo ln -s /usr/bin/nodejs /usr/bin/node
Regarding the issue with administrator access, simply run your commands with sudo at the beginning. Sudo is usually required in situations where modifications to the filesystem are necessary.

Error installing modules for node.js

I installed node and everything was ok, but when I've tried to install stylus, for example didn't allow me to do it with :nmp install -g stylus, only with :npm install stylus.
When I try to compile estilos.styl anywhere, then the console gives me
"command not found"
I tried to install stylus in the local folder too, but still same error. Same happens with grunt-cli or any module I try to install with node.
These are the errors:
iMac-de-Eva:~ eva$ npm install stylus -g npm ERR! Error: EACCES, mkdir
'/usr/local/lib/node_modules/stylus' npm ERR! { [Error: EACCES, mkdir
'/usr/local/lib/node_modules/stylus'] npm ERR! errno: 3, npm ERR!
code: 'EACCES', npm ERR! path: '/usr/local/lib/node_modules/stylus',
npm ERR! fstream_type: 'Directory', npm ERR! fstream_path:
'/usr/local/lib/node_modules/stylus', 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:46: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.5.0 npm ERR! command "node"
"/usr/local/bin/npm" "install" "stylus" "-g" npm ERR! cwd /Users/eva
npm ERR! node -v v0.10.33 npm ERR! npm -v 1.4.28 npm ERR! path
/usr/local/lib/node_modules/stylus npm ERR! fstream_path
/usr/local/lib/node_modules/stylus 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/stylus'
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:46: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/eva/npm-debug.log npm ERR! not ok code 0
If you're trying to install globally (which is what the -g switch means) you may have to use sudo: sudo npm install -g [module-name]
EACASSS error means you do not have permissions.
To install globally you need to have elevated permissions, this will help:
sudo npm install -g stylus
It will ask you for the password for security reasons.
Installing locally works without permissions, but as you noticed, command stylus is not found, because it is installed locally and not included into your $PATH.
Try to install using this:
npm install --save [module-name]

Cannot npm install -g without sudo changing prefix

I have done this: https://stackoverflow.com/a/21712034
now my npm config is the following:
npm config get prefix
/home/ranu/npm
But when I run npm install -g grunt-cli I get:
npm ERR! Error: EACCES, mkdir '/usr/lib/node_modules/grunt-cli'
npm ERR! { [Error: EACCES, mkdir '/usr/lib/node_modules/grunt-cli']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/lib/node_modules/grunt-cli',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/lib/node_modules/grunt-cli',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR! '/usr/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 Linux 3.11.0-26-generic
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "install" "-g" "grunt-cli"
npm ERR! cwd /home/ranu
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! path /usr/lib/node_modules/grunt-cli
npm ERR! fstream_path /usr/lib/node_modules/grunt-cli
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/lib/node_modules/grunt-cli'
npm ERR! fstream_stack /usr/lib/node_modules/npm/node_modules/fstream/lib/dir- writer.js:36:23
npm ERR! fstream_stack /usr/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! /home/ranu/npm-debug.log
npm ERR! not ok code 0
Why is trying to install it on /usr/lib/node_modules/ if the prefix is set to /home/ranu/npm ?
UPDATE:
I could it make it work with the following command:
npm install --prefix="/home/ranu/npm" -g grunt-cli
There is any way to make it as a default?
Every time I get a new Machine, I run into this.
I'm citing this url fixing-npm-permissions because it's actually NPM's doc, but also because it was the only method that fixed my problem. Not the first search result but the simplest fix for me. I'm sure there are more robust fixes.
Rather than copying and pasting, I'm recommending you just go read it.
I followed step 1, and though according to them it should have worked. But, I ended up also using step 2 for the win.
You can use NVM (Node version manager) and you will never have to bother about sudo for npm commands

Cant install npm packages with out sudo

I am trying to install node-debugger and can't install with out sudo. Using sudo gets me some unexpected sideeffects, so want to install with out sudo. Following is the error trace
$ npm install -g node-inspector
npm http GET https://registry.npmjs.org/node-inspector
npm http 304 https://registry.npmjs.org/node-inspector
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/node-inspector'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/node-inspector']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/node-inspector',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/node-inspector',
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 Linux 3.8.0-35-generic
npm ERR! command "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "node-inspector"
npm ERR! cwd /home/santhosh/dev/scaleqa/mean_tut/mean_io_original/scaleqaApp
npm ERR! node -v v0.10.22
npm ERR! npm -v 1.3.14
npm ERR! path /usr/local/lib/node_modules/node-inspector
npm ERR! fstream_path /usr/local/lib/node_modules/node-inspector
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/node-inspector'
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! /home/santhosh/dev/scaleqa/mean_tut/mean_io_original/scaleqaApp/npm-debug.log
npm ERR! not ok code 0
You have to use sudo; this is because when you install globally, NPM creates links from your bin folder(s) to scripts that run node and the specified scripts from the packages (making node-inspector somescript.js really run node /path/to/inspector/node_inspector.js somescript.js.
Those bin folders are protected to those who are not super users, therefore sudo must be used to elevate your access level and allow npm to write to those directories.
You are being asked for sudo because you are installing the npm module globally i.e you are using -g and they are stored in bin which can be accessed by sudo user !
if you do not use -g i.e you install it locally it wont ask for sudo permission!

Create a full directory structure/skeleton through the terminal - expressJS/nodeJS

I have seen some tips on the internet on how to create the full directory structure for a node project with a command line with expressJS.
Here are some examples:
express express-skeleton << http://quickleft.com/blog/getting-started-with-express-in-node
./node_modules/.bin/express -t ejs << http://naholyr.fr/2011/08/ecrire-service-rest-nodejs-express-partie-1/
--l << http://www.techrepublic.com/article/build-nodejs-web-applications-with-express/
But none of those work for me. I have install express and update it to have it globally installed with npm update express -g but my terminal doesn't even recognize the command line express.
How can I build a web app skeleton easily with the command line? Thanks a lot
EDIT: when running the npm install -g express command line, I get this error message:
npm http GET https://registry.npmjs.org/express
npm http 200 https://registry.npmjs.org/express
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/express'
npm ERR! { [Error: EACCES, mkdir '/usr/local/lib/node_modules/express']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/usr/local/lib/node_modules/express',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/usr/local/lib/node_modules/express',
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 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /Users/arnauddrizard/Documents/Dev/RestAPI
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! path /usr/local/lib/node_modules/express
npm ERR! fstream_path /usr/local/lib/node_modules/express
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/express'
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/arnauddrizard/Documents/Dev/RestAPI/npm-debug.log
npm ERR! not ok code 0
npm unable to create folder inside your application folder.
Give sufficient permissons to your folder, I hope that will fix your issue.
What output do you get when you run npm install -g express? The problem is most likely that npm install -g is not installing to somewhere that's in your PATH.

Resources