"Fatal error: Unable to find local grunt." when running "grunt" command

node.jsGruntjs

node.js Problem Overview


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

node.js Solutions


Solution 1 - node.js

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.

Solution 2 - node.js

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 
    

Solution 3 - node.js

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

Solution 4 - node.js

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.

Solution 5 - node.js

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

  1. run npm install grunt-contrib-jshint --save-dev

  2. run npm install grunt-contrib-watch --save-dev

  3. 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

Solution 6 - node.js

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

guntjs getting started step 2.

Solution 7 - node.js

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAshwin HegdeView Question on Stackoverflow
Solution 1 - node.jsasgothView Answer on Stackoverflow
Solution 2 - node.jsDongho YooView Answer on Stackoverflow
Solution 3 - node.jsmpangView Answer on Stackoverflow
Solution 4 - node.jsmrichterView Answer on Stackoverflow
Solution 5 - node.jsNaeem ShaikhView Answer on Stackoverflow
Solution 6 - node.jslingyfhView Answer on Stackoverflow
Solution 7 - node.jsfourfridaysView Answer on Stackoverflow