导致此错误的原因是什么 - “致命错误:无法找到本地咕噜声”

本文翻译自:What is causing this error - “Fatal error: Unable to find local grunt”

I removed the old version of grunt first, then I installed the new grunt version, and then I got this error: 我首先删除了旧版本的grunt,然后我安装了新的grunt版本,然后我收到了这个错误:

D:\\www\\grunt-test\\grunt grunt-cli: The grunt command line interface. D:\\ www \\ grunt-test \\ grunt grunt-cli:grunt命令行界面。 (v0.1.4) (v0.1.4)

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. 如果您看到此消息,则表示未找到Gruntfile或者您的项目未在本地安装grunt。 For more information about installing and configuring grunt, please see the Getting Started guide: http://gruntjs.com/getting-started 有关安装和配置grunt的更多信息,请参阅“入门指南”: http//gruntjs.com/getting-started

Is this because there is not a reference to grunt in my system path? 这是因为我的系统路径中没有对grunt的引用吗? Or something else? 或者是其他东西? I tried to re-install it a few times already. 我试过几次重新安装它。


#1楼

参考:https://stackoom.com/question/wQlY/导致此错误的原因是什么-致命错误-无法找到本地咕噜声


#2楼

I think you don't have a grunt.js file in your project directory. 我认为你的项目目录中没有grunt.js文件。 Use grunt:init , which gives you options such as jQuery, node,commonjs . 使用grunt:init ,它为您提供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: 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

#3楼

Install Grunt in node_modules rather than globally 在node_modules中安装Grunt而不是全局安装

Unable to find local Grunt likely means that you have installed Grunt globally. Unable to find local Grunt可能意味着您已在全球范围内安装了Grunt。

The Grunt CLI insists that you install grunt in your local node_modules directory, so Grunt is local to your project. Grunt CLI坚持要在本地node_modules目录中安装grunt,因此Grunt是您项目的本地目录。

This will fail: 这将失败:

npm install -g grunt

Do this instead: 改为:

npm install grunt --save-dev

#4楼

If you already have a file package.json in the project and it contains grunt in dependency, 如果你在项目中已经有一个文件package.json ,它包含依赖的grunt

  "devDependencies": {
    "grunt": "~0.4.0",

Then you can run npm install to resolve the issue 然后你可以运行npm install来解决这个问题


#5楼

Do

npm install

to install Grunt locally in ./node_modules (and everything else specified in the package.json file) ./node_modules本地安装Grunt(以及package.json文件中指定的所有其他内容)


#6楼

Could be a few problems here depending on what version of grunt is being used. 这可能是一些问题,具体取决于使用的grunt版本。 Newer versions of grunt actually specify that you have a file named Gruntfile.js (instead of the old grunt.js ). 较新版本的grunt实际上指定您有一个名为Gruntfile.js的文件(而不是旧的grunt.js )。

You should have the grunt-cli tool be installed globally (this is done via npm install -g grunt-cli ). 您应该全局安装grunt-cli工具(这可以通过npm install -g grunt-cli )。 This allows you to actually run grunt commands from the command line. 这允许您从命令行实际运行grunt命令。

Secondly make sure you've installed grunt locally for your project. 其次,请确保您已在本地为您的项目安装了grunt。 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. 如果你看到你的package.json没有类似"grunt": "0.4.5"的东西那么你应该在项目目录中执行npm install grunt --save

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值