73

I uninstalled grunt with following command.

npm uninstall -g grunt

Then I again installed grunt with following command.

npm install -g grunt-cli

Visit following link: https://npmjs.org/package/grunt-html

I want to use the above grunt plugin

But when I run the grunt command it gives me following error:

D:\nodeJS\node_modules\grunt-html>grunt
grunt-cli: The grunt command line interface. (v0.1.6)

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
BenMorel
  • 34,448
  • 50
  • 182
  • 322
Ashwin Hegde
  • 857
  • 2
  • 8
  • 11
  • 3
    I don't see how this has anything to do with jQuery. You have to install grunt in your project directory, just as explained in the documentation: http://gruntjs.com/getting-started#installing-grunt-and-gruntplugins. The error message also says: *"[...] or grunt hasn't been installed locally to your project."*. – Felix Kling Mar 18 '13 at 18:03
  • I successfully installed grunt in my project directory. Now how can i used that plugin – Ashwin Hegde Mar 18 '13 at 18:14
  • 1
    You install the plugin and follow the instructions on its project's page, the page you linked to. – Felix Kling Mar 18 '13 at 18:15
  • http://stackoverflow.com/questions/13925916/fatal-error-unable-to-find-local-grunt/13927654#13927654 , this may help – Anshul Dec 30 '13 at 10:41

7 Answers7

177

All is explained quite nicely on gruntjs.com.

Note that installing grunt-cli does not install the grunt task runner! The job of the grunt CLI is simple: run the version of grunt which has been installed next to a Gruntfile. This allows multiple versions of grunt to be installed on the same machine simultaneously.

So in your project folder, you will need to install (preferably) the latest grunt version:

npm install grunt --save-dev

Option --save-dev will add grunt as a dev-dependency to your package.json. This makes it easy to reinstall dependencies.

asgoth
  • 35,552
  • 12
  • 89
  • 98
  • 3
    I didn't downvote you, but probably it was done because your second line is unnecessary and pedantic. – whitneyland Jun 26 '13 at 19:03
  • 3
    @LeeWhitney I've removed the line, I just meant that the error message mentions the link to the getting started guide, which should be the first place to look for answers. – asgoth Jun 26 '13 at 20:47
20

You have to install grunt in your project folder

  1. create your package.json

    $ npm init
    
  2. install grunt for this project, this will be installed under node_modules/. --save-dev will add this module to devDependency in your package.json

    $ npm install grunt --save-dev
    
  3. then create gruntfile.js and run

    $ grunt 
    
Dongho Yoo
  • 1,506
  • 16
  • 16
  • 2
    Also, make sure that the node-modules folder is being created. Mine wasn't because npm had `global=true` configuration. I've found the solution here: http://stackoverflow.com/a/13449393/1046584 – Luís Bianchin Jul 25 '14 at 03:51
4

I think you have to add grunt to your package.json file. See this link.

mpang
  • 311
  • 1
  • 4
  • 13
4

I had this issue on my Windows grunt because I installed the 32 bit version of Node on a 64 bit Windows OS. When I installed the 64bit version specifically, it started working.

mrichter
  • 103
  • 1
  • 8
1

I had the same issue today on windows 32 bit,with node 0.10.25, and grunt 0.4.5.

I followed dongho's answer, with just few extra steps. here are the steps I used to solve the error:

1) create your package.json

$ npm init

2) install grunt for this project, this will be installed under node_modules/. --save-dev will add this module to devDependency in your package.json

$ npm install grunt --save-dev

3) then create gruntfile.js , with a sample code like this:

module.exports = function(grunt) {

  grunt.initConfig({
    jshint: {
      files: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'],
      options: {
        globals: {
          jQuery: true
        }
      }
    },
    watch: {
      files: ['<%= jshint.files %>'],
      tasks: ['jshint']
    }
  });

  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');

  grunt.registerTask('default', ['jshint']);

};

here, src/**/*.js and test/**/*.js should be the paths to actual JS files you are using in your project

4) run npm install grunt-contrib-jshint --save-dev

5) run npm install grunt-contrib-watch --save-dev

6) run $ grunt

Note: when you require common package like concat, uglify etc, you need to add those modules via npm install, just the way we installed jshint and watch in step 4 & 5

Community
  • 1
  • 1
Naeem Shaikh
  • 15,331
  • 6
  • 50
  • 88
1

if you are a exists project, maybe should execute npm install.

guntjs getting started step 2.

lingyfh
  • 1,363
  • 18
  • 23
1

This solved the issue for me. I mistakenly installed grunt using:

sudo npm install -g grunt --save-dev

and then ran the following command in the project folder:

npm install

This resulted in the error seen by the author of the question. I then uninstalled grunt using:

sudo npm uninstall -g grunt

Deleted the node_modules folder. And reinstalled grunt using:

npm install grunt --save-dev

and running the following in the project folder:

npm install

For some odd reason when you global install grunt using -g and then uninstall it, the node_modules folder holds on to something that prevents grunt from being installed locally to the project folder.