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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13925916/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 15:08:13  来源:igfitidea点击:

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

javascriptgruntjs

提问by Ryan Yiada

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. (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. For more information about installing and configuring grunt, please see the Getting Started guide: http://gruntjs.com/getting-started

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

致命错误:无法找到本地咕噜声。

如果您看到此消息,则说明未找到 Gruntfile 或尚未将 grunt 安装到您的项目本地。有关安装和配置 grunt 的更多信息,请参阅入门指南:http: //gruntjs.com/getting-started

Is this because there is not a reference to grunt in my system path? Or something else? I tried to re-install it a few times already.

这是因为我的系统路径中没有对 grunt 的引用吗?或者是其他东西?我已经尝试重新安装它几次了。

采纳答案by Anshul

I think you don't have a grunt.jsfile 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.

我认为您grunt.js的项目目录中没有文件。使用grunt:init,它为您提供诸如jQuery, node,commonjs. 选择你想要的,然后继续。这确实有效。有关更多信息,您可以访问

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

回答by superluminary

Install Grunt in node_modules rather than globally

在 node_modules 中而不是全局安装 Grunt

Unable to find local Gruntlikely 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 坚持将 grunt 安装在本地 node_modules 目录中,因此 Grunt 对您的项目来说是本地的。

This will fail:

这将失败:

npm install -g grunt

Do this instead:

改为这样做:

npm install grunt --save-dev

回答by Klas Mellbourn

Do

npm install

to install Grunt locally in ./node_modules(and everything else specified in the package.jsonfile)

在本地安装 Grunt ./node_modules(以及package.json文件中指定的所有其他内容)

回答by Anthony Kong

If you already have a file package.jsonin the project and it contains gruntin dependency,

如果package.json项目中已经有一个文件并且它包含grunt依赖项,

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

Then you can run npm installto resolve the issue

然后你可以运行npm install来解决问题

回答by Tomer Ben David

It says you don't have a local gruntso try:

它说你没有本地人grunt所以试试:

npm install grunt

npm install grunt

(without the -git's a local grunt)

(没有-g它是本地的grunt

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

虽然没有直接关系,但请确保您Gruntfile.js在当前文件夹中。

回答by misterzik

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

我错误地使用 sudo 和其他没有权限安装了一些软件包,这解决了我的问题。

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

hope it helps someone.

希望它可以帮助某人。

回答by Nick Schaubeck

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

根据使用的 grunt 版本,这里可能会出现一些问题。较新版本的 grunt 实际上指定您有一个名为Gruntfile.js(而不是旧的grunt.js)的文件。

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

您应该grunt-cli全局安装该工具(这是通过 完成的npm install -g grunt-cli)。这允许您grunt从命令行实际运行命令。

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

其次,确保你已经在本地为你的项目安装了 grunt。如果你看到你的里面package.json没有类似的东西"grunt": "0.4.5",那么你应该npm install grunt --save在你的项目目录中做。

回答by Max

I had to execute the following commands on ubuntu to solve this problem (I know grunt for 1 hour) :

我不得不在 ubuntu 上执行以下命令来解决这个问题(我知道 grunt 1 小时):

sudo npm install -g grunt
sudo npm install -g grunt-cli

cd /usr/local/bin
# current symlink points to ../lib/node_modules/grunt/bin/grunt*
sudo rm /usr/local/bin/grunt
sudo ln -s ../lib/node_modules/grunt-cli/bin/grunt* grunt

It is dirty but it is the only one solution I found... :(

它很脏,但它是我找到的唯一一种解决方案...... :(

回答by mlncn

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:

以上都不对我有用,因为我在全球范围内安装了 grunt(奇怪的是,在其中几个答案中推荐),这把一切都搞砸了。这是有效的:

npm uninstall -g grunt
npm install

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

直到现在才安装了本地 grunt,并且对我有用。

回答by user1012513

I had the same issue in Vagrant.

我在 Vagrant 中遇到了同样的问题。

I have used sudo to run the command to install.

我已经使用 sudo 运行命令进行安装。

sudo npm install -g grunt-cli

It worked for me.

它对我有用。