grunt: command not found - node.js

npm knows that grunt is installed globally, so why isn't it found?
$ npm install -g grunt
... installs ...
$ npm list -g | grep grunt
│ ├─┬ gruntfile-editor#0.2.0
│ ├─┬ gruntfile-editor#0.2.0
├─┬ grunt#0.4.5
│ ├─┬ grunt-legacy-log#0.1.1
│ ├── grunt-legacy-util#0.2.0
$ grunt
-bash: grunt: command not found
I assume because it's put it somewhere that is not on my PATH.
Why doesn't npm just put it somewhere that is on my PATH by default, like /usr/local/bin?
UPDATE: Weirdly, I get the same grunt: command not found error even after I do npm install grunt to run it locally. What am I doing wrong? There is a Gruntfile.js in my repo.

The package "grunt" is the task runner itself whereas the "grunt-cli" package is the command line interface that includes the grunt executable. You can make sure that it is installed to the correct path.
If you do npm install grunt-cli it still would not work because this would be installed to node_modules in the corresponding directory which is most likely not on your path. However, when you use grunt from the globally installed CLI tool it will look for an installation of grunt that is local to that project as well as the Gruntfile.js
what you have to do is
install grunt-cli globally:
$ npm install grunt-cli -g
install grunt local in your dependencies (optionally save the dependency to your package.json):
$ npm install grunt --save

For me there was another thing missing, adding the path to NPM's folder in Window's env variables
Go to System (My computer->Properties)
Advanced System Settings
In Advanced tab, 'Environment Variables'
Under User variables, choose Path, then Edit
Add this alongside the others you have: '%USERPROFILE%\AppData\Roaming\npm'
Hope this helps, g'luck

Related

Strange npm behavior when installing packages like grunt

I run the following command in my bash and I get the related results:
merianos#merianos-desktop:~$ sudo npm install -g grunt-cli
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
grunt-cli#0.1.13 /usr/local/lib/node_modules/grunt-cli
├── resolve#0.3.1
├── nopt#1.0.10 (abbrev#1.0.7)
└── findup-sync#0.1.3 (lodash#2.4.2, glob#3.2.11)
and
merianos#merianos-desktop:~$ grunt
/usr/bin/env: node: No such file or directory
I also have try to install bower and gulp but again, when I try to execute them, I get a message related to the grunt above.
Can someone please help me ?
Just to know, I just installed Ubuntu 15.04. I don't know if that helps :)
Ubuntu package nodejs provide a binary as a /usr/bin/nodejs, not a /usr/bin/node, so most of cli tools can't find it. To solve the problem you need to make a symlink:
sudo ln -sT /usr/bin/nodejs /usr/bin/node

npm not installing any module

I am new to node.js.
I have installed node.js and I tested the installation is ok. node -v and npm -v command are showing the version numbers.
But when I install any module it's not working.
For example when I try to install the connect module using npm install connect, it's showing following result.
C:\>npm install connect
connect#3.3.5 node_modules\connect
├── utils-merge#1.0.0
├── parseurl#1.3.0
├── debug#2.1.3 (ms#0.7.0)
└── finalhandler#0.3.4 (escape-html#1.0.1, on-finished#2.2.0)
C:\>
Kindly help me out.
That installed it. However it installed it "locally" (to the current folder) and not globally. If you want to install it globally then use -g.
npm install -g connect

Can no longer run any node packages after reinstall

My node suddenly stopped working so I removed everything and installed node with homebrew.
Now I cant install grunt, nodemon, bower etc.
Pers-MacBook-Air:backendMD perstrom$ sudo npm install -g grunt-cli
Password:
/Users/perstrom/.node/bin/grunt -> /Users/perstrom/.node/lib/node_modules/grunt-cli/bin/grunt
grunt-cli#0.1.13 /Users/perstrom/.node/lib/node_modules/grunt-cli
├── resolve#0.3.1
├── nopt#1.0.10 (abbrev#1.0.5)
└── findup-sync#0.1.3 (lodash#2.4.1, glob#3.2.11)
Pers-MacBook-Air:backendMD perstrom$ grunt --version
bash: grunt: command not found
Pers-MacBook-Air:backendMD perstrom$
What can be wrong? How do I debug this?
Try to expend your path (make sure this folder contains the bins):
export PATH=/Users/perstrom/.node/bin:$PATH

Cannot install express-generator globally with nvm

I'm using NVM to avoid using sudo to install things globally. It works fine for everything from Bower, to Grunt, etc. However, when I do npm install -g express-generator it doesnt work. For example, heres what I get when I globally install Bower:
npm install -g bower
/Users/jrdillon522/.node/bin/bower -> /Users/jrdillon522/.node/lib/node_modules/bower/bin/bower
bower#1.3.12 /Users/jrdillon522/.node/lib/node_modules/bower
├── is-root#1.0.0
...
...
...
├── update-notifier#0.2.0 (semver-diff#0.1.0, string-length#0.1.2, latest-version#0.2.0, configstore#0.3.1)
├── mout#0.9.1
├── handlebars#2.0.0 (optimist#0.3.7, uglify-js#2.3.6)
├── inquirer#0.7.1 (figures#1.3.3, mute-stream#0.0.4, through#2.3.6, readline2#0.1.0, lodash#2.4.1, cli-color#0.3.2, rx#2.3.14)
└── insight#0.4.3 (object-assign#1.0.0, async#0.9.0, chalk#0.5.1, os-name#1.0.1, lodash.debounce#2.4.1, tough-cookie#0.12.1, configstore#0.3.1, inquirer#0.6.0)
Works fine right? When I install the Express Generator I get the classic error:
npm ERR! Please try running this command again as root/Administrator.
So I run sudo npm install -g express-generator. Heres what I get then:
sudo npm install -g express-generator
Password:
/Users/myName/.node/bin/express -> /Users/myName/.node/lib/node_modules/express-generator/bin/express
express-generator#4.9.0 /Users/myName/.node/lib/node_modules/express-generator
├── mkdirp#0.5.0 (minimist#0.0.8)
└── commander#1.3.2 (keypress#0.1.0)
➜ ~ express -v
zsh: command not found: express
➜ ~
Why??
It looks like your bin path (/Users/myName/.node/lib/node_modules/express-generator/bin/express) isn't added to your environment.
If you modify your .bashrc file, add the following line to the bottom of your file to make things work as expected:
export PATH=$PATH:/Users/myName/.node/lib/node_modules/express-generator/bin
Then retry the installation.

Cannot find module 'findup-sync' when trying to run grunt

I am having trouble running grunt-cli after installing it. I run
npm install -g grunt-cli
then running grunt errors with
node.js:63
throw e;
^
Error: Cannot find module 'findup-sync'
at loadModule (node.js:275:15)
at require (node.js:411:14)
at Object.<anonymous> (/home/tmartin/bin/grunt:9:14)
at Module._compile (node.js:462:23)
at Module._loadScriptSync (node.js:469:10)
at Module.loadSync (node.js:338:12)
at Object.runMain (node.js:522:24)
at Array.<anonymous> (node.js:756:12)
at EventEmitter._tickCallback (node.js:55:22)
at node.js:773:9
This is what I have installed:
tmartin#timcomp:~$ npm list -g
/home/tmartin/lib
└─┬ grunt-cli#0.1.6
├─┬ findup-sync#0.1.2
│ ├─┬ glob#3.1.21
│ │ ├── graceful-fs#1.2.0
│ │ ├── inherits#1.0.0
│ │ └─┬ minimatch#0.2.11
│ │ ├── lru-cache#2.2.2
│ │ └── sigmund#1.0.0
│ └── lodash#1.0.1
└─┬ nopt#1.0.10
└── abbrev#1.0.4
I had to install and link findup-sync and a few other npm packages to get these dependency issues to go away. I though npm was supposed to handle them for us, but installing the dependencies manually made the issues go away.
npm install findup-sync -g
npm link findup-sync
I got mine running again reinstalling grunt-cli globally and in my repo.
npm install -g grunt-cli
cd myrepo
npm install grunt-cli
I think Yosemite installation broke some things in my files ...
This is because npm doesn't set the right permission to sub-directory node_modules in /usr/lib/node_modules/grunt-cli.
In my case, I had:
drwxr-x--- 6 nobody root 4096 16 févr. 17:08 node_modules
When running grunt as non-root user, I had the same error (Cannot find module 'findup-sync') because of a permission denied to read this directory.
The solution is to fix permission with chmod: chmod a+rx node_modules.
But in fact, all directories was involved. The best way was to todo:
find /usr/lib/node_modules/grunt-cli -type d -exec chmod a+rx {} \;
This is maybe a distribution bug (I use Archlinux).
This may seem simple, but if anyone else is unsure if there's a permissions problem, try running sudo grunt then go from there.
I use NVM and was having this problem whenever I changed the active node version.
Following #davidcondrey 's suggestion worked for me. The catch really was to install grunt-cli before grunt. The order made a difference and fixed it.
npm i -g grunt-cli grunt
#inostia 's answer of using sudo to test the permissions was OK, but gave me quite a headache with file permissions, as all the grunt-processed files were inacessible by git later and broke my versioning.
This also may be obvious, but in my case I had set up my npm path off my home directory (on a chromebook) and needed to add .node_modules to my .profile
PATH=~./node_modules:$PATH
Then run:
source ~/.profile
I was able to fix this by reinstalling Grunt using these commands:
sudo npm remove -g grunt-cli
sudo npm install -g grunt-cli
This issue occurs if you change your NodeJS version.
After changing the node version, re installing grunt or npm install will resolve the issue.
Tried all the answers above and I could not get grunt to work without using sudo
Finally came across this Wordpress article and deleted the link to /usr/local/lib/node_modules/grunt/bin/grunt
lrwxrwxrwx 1 root root 35 Apr 19 22:45 /usr/local/bin/grunt -> ../lib/node_modules/grunt/bin/grunt
using sudo rm /usr/local/bin/grunt
Then I linked to the grunt executable in /usr/local/lib/node_modules/grunt-cli/bin
using sudo ln -s /usr/local/lib/node_modules/grunt-cli/bin/grunt /usr/local/bin/grunt
Now, I can run grunt without using sudo
I solved this by running:
npm install -gg grunt-cli --force

Resources