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

前端 未结 7 422
猫巷女王i
猫巷女王i 2021-01-30 08:11

I uninstalled grunt with following command.

npm uninstall -g grunt

Then I again installed grunt with following command.

npm ins         


        
相关标签:
7条回答
  • 2021-01-30 08:37

    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.

    0 讨论(0)
  • 2021-01-30 08:38

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

    guntjs getting started step 2.

    0 讨论(0)
  • 2021-01-30 08:46

    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.

    0 讨论(0)
  • 2021-01-30 08:56

    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 
      
    0 讨论(0)
  • 2021-01-30 08:56

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

    0 讨论(0)
  • 2021-01-30 08:58

    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

    0 讨论(0)
提交回复
热议问题