"致命错误:无法找到当地的咕噜声." 当运行"grunt"命令时

Ash*_*gde 73 node.js gruntjs

我用以下命令卸载了grunt.

npm uninstall -g grunt
Run Code Online (Sandbox Code Playgroud)

然后我再次使用以下命令安装grunt.

npm install -g grunt-cli
Run Code Online (Sandbox Code Playgroud)

请访问以下链接:https: //npmjs.org/package/grunt-html

我想使用上面的grunt插件

但是当我运行grunt命令时,它会给我以下错误:

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
Run Code Online (Sandbox Code Playgroud)

asg*_*oth 174

所有这些都在gruntjs.com上得到了很好的解释.

请注意,安装grunt-cli不会安装grunt任务运行器!grunt CLI的工作很简单:运行已经安装在Gruntfile旁边的grunt版本.这允许多个版本的grunt同时安装在同一台机器上.

所以在你的项目文件夹中,你需要安装(最好)最新的grunt版本:

npm install grunt --save-dev
Run Code Online (Sandbox Code Playgroud)

选项--save-dev将grunt作为dev-dependency添加到package.json中.这样可以轻松地重新安装依赖项.

  • 我没有向你投票,但可能是因为你的第二行是不必要的和迂腐的. (3认同)
  • @LeeWhitney我已删除该行,我只是意味着错误消息提到了入门指南的链接,这应该是寻找答案的第一个地方. (3认同)

Don*_*Yoo 20

您必须在项目文件夹中安装grunt

  1. 创建你的package.json

    $ npm init
    
    Run Code Online (Sandbox Code Playgroud)
  2. 为这个项目安装grunt,这将安装在node_modules/.--save-dev会将此模块添加到package.json中的devDependency

    $ npm install grunt --save-dev
    
    Run Code Online (Sandbox Code Playgroud)
  3. 然后创建gruntfile.js并运行

    $ grunt 
    
    Run Code Online (Sandbox Code Playgroud)

  • 此外,请确保正在创建node-modules文件夹.我不是因为npm有'global = true`配置.我在这里找到了解决方案:http://stackoverflow.com/a/13449393/1046584 (2认同)