node.js 无法让 Gulp 运行:找不到模块“gulp-util”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21406738/
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-09-02 16:46:23  来源:igfitidea点击:

Can't get Gulp to run: cannot find module 'gulp-util'

node.jsnpmgulp

提问by Nicolas Le Thierry d'Ennequin

On Windows 7, I've installed gulp as explained here: http://markgoodyear.com/2014/01/getting-started-with-gulp/:

在 Windows 7 上,我已经按照此处的说明安装了 gulp:http: //markgoodyear.com/2014/01/getting-started-with-gulp/

  • npm install gulp -g
  • In my app folder: npm install gulp --save-dev
  • I create a gulpfile.jsfile.
  • npm install gulp -g
  • 在我的应用程序文件夹中: npm install gulp --save-dev
  • 我创建一个gulpfile.js文件。

But then, when I try to run gulp, I get this error message:

但是,当我尝试运行时gulp,我收到此错误消息:

module.js:340
throw err;
      ^
Error: cannot file module 'gulp-util'
at Function.Module._resolveFilename (module.js:338:15)

etc.

等等。

But gulp-utilis present (in the local app folder) in:

但是gulp-util存在于(在本地应用程序文件夹中):

node_modules
    gulp
        node_modules
            gulp-util

Any idea what may be the cause?

知道可能是什么原因吗?

回答by Ilan Frumer

UPDATE

更新

From later versions, there is no need to manually install gulp-util.

从更高版本开始,无需手动安装 gulp-util。

Check the new getting started page.

检查新的入门页面

If you still hit this problem try reinstalling your project's local packages:

如果您仍然遇到此问题,请尝试重新安装项目的本地包:

rm -rf node_modules/
npm install


OUTDATED ANSWER

过时的答案

You also need to install gulp-util:

你还需要安装 gulp-util:

 npm install gulp-util --save-dev

From gulp docs- getting started (3.5):

来自gulp 文档-入门(3.5)

Install gulp and gulp-utilin your project devDependencies

在你的项目 devDependencies 中安装gulp 和 gulp -util

回答by numediaweb

If you have a package.json, you can install all the current project dependencies using:

如果您有 package.json,则可以使用以下命令安装所有当前项目依赖项:

npm install

回答by timfrostmann

Any answer didn't help in my case. What eventually helped was removing bowerand gulp(I use both of them in my project):

在我的情况下,任何答案都没有帮助。最终有帮助的是删除bowergulp(我在我的项目中同时使用了它们):

npm remove -g bower
npm remove -g gulp

After that I installed them again:

之后我再次安装它们:

npm install -g bower
npm install -g gulp

Now it works just fine.

现在它工作得很好。

回答by C-Note187

Linux Ubuntu 18:04user here. I tried all the solutions on this board to date. Even though I read above in the accepted answer that "From later versions, there is no need to manually install gulp-util.", it was the thing that worked for me.(...maybe bc I'm on Ubuntu? I don't know. )

Linux Ubuntu 18:04用户在这里。迄今为止,我尝试了该板上的所有解决方案。即使我在上面接受的答案中读到“从更高版本开始,无需手动安装 gulp-util”。,这对我有用。(...也许 bc 我在 Ubuntu 上?我不知道。)

To recap, I kept getting the "cannot find module 'gulp-util'" error when just checking to see if gulp was installed by running:

回顾一下,当我通过运行检查是否安装了 gulp 时,我不断收到“找不到模块‘gulp-util’”错误:

gulp --version

...again, the 'gulp-util' error kept appearing...

...再次,'gulp-util' 错误不断出现...

So, I followed the npm install [package name] advice listed above, but ended up getting several other packages that needed to be installed as well. And one had a issue of already existing, and i wasn't sure how to replace it. ...I will put all the packages/install commands that I had to use here, just as reference in case someone else experiences this problem:

所以,我遵循了上面列出的 npm install [package name] 建议,但最终得到了其他几个需要安装的软件包。并且有一个已经存在的问题,我不知道如何替换它。...我将把我必须使用的所有包/安装命令放在这里,作为参考,以防其他人遇到这个问题:

sudo npm install -g gulp-util

(then I got an error for 'pretty-hrtime' so I added that, and then the others as Error: Cannot find module ___ kept popping up after each gulp --version check. ...so I just kept installing each one.)

(然后我收到了'pretty-hrtime'的错误,所以我添加了它,然后其他错误:无法找到模块___在每次gulp --version检查后不断弹出。......所以我只是继续安装每个。 )

sudo npm install -g pretty-hrtime
sudo npm install -g chalk
sudo npm install -g semver --force

(without --force, on my system I got an error: "EEXIST: file already exists, symlink". --force is not recommended, but idk any other way. )

(没有--force,在我的系统上,我收到一个错误:“EEXIST:文件已经存在,符号链接”。不推荐使用--force,但可以通过其他方式识别。)

sudo npm install -g archy
sudo npm install -g liftoff
sudo npm install -g tildify
sudo npm install -g interpret
sudo npm install -g v8flags
sudo npm install -g minimist

And now gulp --version is finally showing: CLI version 3.9.1 Local version 3.9.1

现在 gulp --version 终于显示:CLI version 3.9.1 Local version 3.9.1

回答by xatz

Try to install the missing module.

尝试安装缺少的模块。

npm install 'module-name'

回答by Nikita Jajodia

You should install these as devDependencies:
- gulp-util
- gulp-load-plugins

您应该安装这些为devDependencies:
- gulp-util
-gulp-load-plugins

Then, you can use them either this way:

然后,您可以通过以下方式使用它们:

var plugins     = require('gulp-load-plugins')();
Use gulp-util as : plugins.util()

or this:

或这个:

var util = require('gulp-util')

回答by kedar kokil

This will solve all gulp problem

这将解决所有吞咽问题

sudo npm install gulp && sudo npm install --save del && sudo gulp build

回答by Mother10

Same issue here and whatever I tried after searching around, did not work. Until I saw a remark somewhere about global or local installs. Looking in:

同样的问题在这里以及我在四处搜索后尝试的任何内容都不起作用。直到我在某处看到有关全局或本地安装的评论。在看:

C:\Users\YourName\AppData\Roaming\npm\gulp

C:\Users\YourName\AppData\Roaming\npm\gulp

I indeed found an outdated version. So I reinstalled gulp with:

我确实找到了一个过时的版本。所以我重新安装了 gulp:

npm install gulp --global

That magically solved my problem.

这神奇地解决了我的问题。

回答by Balram Singh

In most of the cases, deleting all the node packages and then installing them again, solve the problem.

在大多数情况下,删除所有节点包然后重新安装它们,可以解决问题。

But In my case node_modules folder has not write permission.

但就我而言, node_modules 文件夹没有写权限。

回答by Nayan

I had the same issue, although the module that it was downloading was different. The only resolution to the problem is run the below command again:

我有同样的问题,虽然它下载的模块不同。该问题的唯一解决方案是再次运行以下命令:

npm install