What is causing this error - “Fatal error: Unable to find local grunt”

前端 未结 13 559
夕颜
夕颜 2020-11-27 09:21

I removed the old version of grunt first, then I installed the new grunt version, and then I got this error:

D:\\www\\grunt-test\\grunt grunt-cli: The

相关标签:
13条回答
  • 2020-11-27 09:32

    I made the mistake to install some packages using sudo and other without privileges , this fixed my problem.

    sudo chown -R $(whoami) $HOME/.npm
    

    hope it helps someone.

    0 讨论(0)
  • 2020-11-27 09:32

    Could be a few problems here depending on what version of grunt is being used. Newer versions of grunt actually specify that you have a file named Gruntfile.js (instead of the old grunt.js).

    You should have the grunt-cli tool be installed globally (this is done via npm install -g grunt-cli). This allows you to actually run grunt commands from the command line.

    Secondly make sure you've installed grunt locally for your project. If you see your package.json doesn't have something like "grunt": "0.4.5" in it then you should do npm install grunt --save in your project directory.

    0 讨论(0)
  • 2020-11-27 09:32

    None of the above worked for me because i had grunt installed globally (recommended in several of these answers, oddly) and that was messing everything up. Here's what did work:

    npm uninstall -g grunt
    npm install
    

    Only now was a local grunt installed, and useable, for me.

    0 讨论(0)
  • 2020-11-27 09:34

    It says you don't have a local grunt so try:

    npm install grunt

    (without the -g it's a local grunt)

    Though not directly related, make sure you have Gruntfile.js in your current folder.

    0 讨论(0)
  • 2020-11-27 09:35

    I think you don't have a grunt.js file in your project directory. Use grunt:init, which gives you options such as jQuery, node,commonjs. Select what you want, then proceed. This really works. For more information you can visit this.

    Do this:

     1. npm install -g grunt
     2. grunt:init  ( you will get following options ):
          jquery: A jQuery plugin
          node: A Node module
          commonjs: A CommonJS module
          gruntplugin: A Grunt plugin
          gruntfile: A Gruntfile (grunt.js)
     3 .grunt init:jquery (if you want to create a jQuery related project.).
    

    It should work.

    Solution for v1.4:

    1. npm install -g grunt-cli
    2. npm init
       fill all details and it will create a package.json file.
    3. npm install grunt (for grunt dependencies.)
    

    Edit : Updated solution for new versions:

     npm install grunt --save-dev
    
    0 讨论(0)
  • 2020-11-27 09:35

    Install Grunt in node_modules rather than globally

    Unable to find local Grunt likely means that you have installed Grunt globally.

    The Grunt CLI insists that you install grunt in your local node_modules directory, so Grunt is local to your project.

    This will fail:

    npm install -g grunt
    

    Do this instead:

    npm install grunt --save-dev
    
    0 讨论(0)
提交回复
热议问题