49

I installed yeoman and started the examples which are provided in the official documentation. I went through the suggested operations

    yo webapp 
    bower install underscore  
    grunt

After running grunt I have the message

    grunt-cli: The grunt command line interface. (v0.1.9)

    Fatal error: Unable to find local grunt.

    If you're seeing this message, either a Gruntfile wasn't found or grunt
    hasn't been installed locally to your project. For more information about
    installing and configuring grunt, please see the Getting Started guide:

    http://gruntjs.com/getting-started

Note that grunt have been installed with

    npm install -g grunt-cli

and

    npm install -g grunt

yo has generated the Gruntfile.js in the project root, where I am running the command.
The package.json has been generated as well:

    "name": "testyo",
    "version": "0.0.0",
    "dependencies": {},
    "devDependencies": {
      "grunt": "~0.4.1",
      "grunt-contrib-copy": "~0.4.1",
      "grunt-contrib-concat": "~0.1.3",
      "grunt-contrib-coffee": "~0.6.5",
      "grunt-contrib-uglify": "~0.2.0",
      "grunt-contrib-compass": "~0.2.0",
      "grunt-contrib-jshint": "~0.4.1",
      "grunt-contrib-cssmin": "~0.6.0",
      "grunt-contrib-connect": "~0.2.0",
      "grunt-contrib-clean": "~0.4.0",
      "grunt-contrib-htmlmin": "~0.1.3",
      "grunt-contrib-imagemin": "~0.1.3",
      "grunt-contrib-watch": "~0.4.0",
      "grunt-rev": "~0.1.0",
      "grunt-autoprefixer": "~0.1.20130516",
      "grunt-usemin": "~0.1.10",
      "grunt-mocha": "~0.3.0",
      "grunt-open": "~0.2.0",
      "grunt-svgmin": "~0.1.0",
      "grunt-concurrent": "~0.1.0",
      "matchdep": "~0.1.1",
      "connect-livereload": "~0.2.0"
    },
    "engines": {
      "node": ">=0.8.0"
    }

Additionally. From the root directory

    grunt --version
    grunt-cli v0.1.9

This confirm that grunt is available to be run in every directory.
Any idea?

blackbird014
  • 2,069
  • 1
  • 18
  • 23

3 Answers3

90

After some quick research I realized, from the grunt documentation, that grunt has to be installed in the project. I did that by running:

    sudo npm install grunt --save-dev

Now grunt works.

I also needed to run:

    npm install

so that all the dependencies are loaded.

This solved my problem. To be honest I thought yeoman would have taken care of the last two steps automatically.

In case you have comments or think there is a better solution, please leave a comment.

slamborne
  • 1,185
  • 11
  • 16
blackbird014
  • 2,069
  • 1
  • 18
  • 23
  • 7
    After scaffolding, Yeoman automatically calls `npm install` as well as `bower install`. Like everything in the software world, sometimes bugs come up. For some reason, during your scaffolding, the process must have escaped too soon from an error, preventing `npm install` to have been run by default. – Stephen Aug 08 '13 at 17:40
  • 1
    thanx for your reply. I already checked all the source code :-). Left my post in case can be useful for some other person new to yeoman. – blackbird014 Aug 09 '13 at 07:12
  • weird, I just had to redo npm install when I changed git branches from my non angular branch back to my angular one – shicholas Sep 20 '13 at 17:58
  • Thanks for this. Was going insane trying to find out why grunt wasn't working. Turns out the initial npm install for grunt and yeoman (triedboth) didn't run an npm install. Worked! Thanks! – James M Jan 15 '14 at 14:28
  • Worked for me as well! – bobber205 Jan 27 '14 at 04:32
  • Had a similar problem on Ubuntu Linux 12.10. This solved my issue too. Thx! +1 to both – CharlieTuna Feb 13 '14 at 10:46
  • Thanks for the tip. Please consider checking out [npm's docs on using sudo with npm](https://docs.npmjs.com/getting-started/fixing-npm-permissions). – HoppyKamper Feb 18 '16 at 00:56
13
npm cache clean
sudo npm install grunt --save-dev

really did the trick for me

Paulo Almeida
  • 2,159
  • 2
  • 17
  • 19
  • 1
    I am on OS X - and this fixed mine as well. Thank you for sharing, without your tip I would have been searching longer. For anyone reading and is new to Grunt - also install Bower. – Greg L Mar 23 '14 at 23:30
2

I ran into the same problem.

After running npm install, make sure a node_modules folder is created in the root of your project. This is the folder where "local grunt" will be placed. If the folder is not there, check your npm cofiguration npm config ls and make sure you have global=false.

I've found the solution here: https://stackoverflow.com/a/13449393/1046584

Community
  • 1
  • 1
Luís Bianchin
  • 2,327
  • 1
  • 28
  • 36