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

12

178

On Windows 7, I've installed gulp as explained here: 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.js file.

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

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

etc.

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

node_modules
    gulp
        node_modules
            gulp-util

Any idea what may be the cause?

Krishnakrishnah answered 28/1, 2014 at 13:22 Comment(1)
try npm install gulp-util --save-devMonika
M
296

UPDATE

From later versions, there is no need to manually install 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:

 npm install gulp-util --save-dev

From gulp docs- getting started (3.5):

Install gulp and gulp-util in your project devDependencies

Monika answered 28/1, 2014 at 13:33 Comment(5)
and if you're on Windows, you can use rimraf via npm install -g rimrafPilgrimage
So with a 150K views on this question alone, I'd love to know what the root cause of this is... This occurs quite frequently for me and I'm guessing I'm not the only one. This adds up to a lot of wasted time!Profit
Just found this evening I had 2 npm installs. On windows under users/name/appdata/roaming I removed node_modules and npm as well as npm-cache. Before removing these I had npm --version 3.x now it shows npm--version 5.6.0 ... might be an issue for others.Farlay
On Ubuntu 17.10, rm -rf node_modules and npm install didn't work. Instead, I had to preform: npm install gulp -g. Works like a charm!Nonconcurrence
The "new getting started page" has moved again, what is the correct URL? github.com/gulpjs/gulp/tree/master/docs/getting-started does not seem to mention gulp-util.Kuster
P
67

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

npm install
Phasia answered 31/7, 2014 at 13:49 Comment(2)
I don't know why in my case, this did not work. I had to install one by one of the missing packages. And then do the build. Weird.Eloquence
@LincolnPiress I did the same to about half-way. But there were a lot. I ran npm install node-sass and it built.Ferdy
M
23

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

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.

Marita answered 2/8, 2016 at 11:32 Comment(3)
This fixed a persistent issue I had with gulp-util not finding through2 despite it being present in the local node_modules folder and repeated 'rm -rf node_module' attempts. Removal and reinstallation of global gulp did the trick.Tutto
I had the problem on windows and the only fix was this one, but before I needed to repair node install using msi filePar
This was the only answer that worked for me too. (I had to add sudo though)Waadt
S
12

Linux Ubuntu 18:04 user 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. )

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

gulp --version

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

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:

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

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

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

Skylab answered 5/1, 2020 at 9:2 Comment(0)
P
8

Try to install the missing module.

npm install 'module-name'
Pastor answered 31/8, 2015 at 15:47 Comment(0)
C
6

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

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

npm install gulp --global

That magically solved my problem.

Chon answered 9/2, 2019 at 14:43 Comment(1)
every time i run into gulp problems, this solves everything.Esmeraldaesmerelda
I
5

You should install these as 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')
Isaiasisak answered 21/1, 2016 at 17:14 Comment(0)
S
4

This will solve all gulp problem

sudo npm install gulp && sudo npm install --save del && sudo gulp build
Sciolism answered 23/5, 2018 at 7:16 Comment(0)
C
4

None of the other answers listed here-- at least by themselves-- solved this for me.

I'm using Ubuntu 20.04 on Windows Linux Subsystem (WSL2). After reinstalling gulp globally with npm install gulp -g seemingly I needed to log out of my WSL instance and log back in again (closing and reopening my CLI was enough).

Hopefully this helps someone else.

Crifasi answered 24/1, 2022 at 19:33 Comment(0)
P
2

I'm using Linux Mint 20.3. Had this error. Nothing helped.

gulp --version
node:internal/modules/cjs/loader:988
  throw err;
  ^

Error: Cannot find module 'gulp-cli'

Found a solution after 2 hours of trying different things. "sudo" ! simple as that.

sudo gulp --version
CLI version: 2.3.0
Local version: 3.9.1

Some gulp commands should be used with sudo to avoid errors

Preamble answered 14/10, 2022 at 10:44 Comment(2)
Not "almost every command should be used with sudo"! Please restrict this advice to the specific web runners, package managers etc. you mean. DO NOT RUN JUST ANY COMMAND WITH sudo, @arec!Peregrine
Yes, my mistake. Some of the gulp commands need to be used with sudo, otherwise response with errorsPreamble
L
1

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

But In my case, the node_modules folder has no write permission.

Longobard answered 9/3, 2016 at 14:12 Comment(0)
M
-2

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
Mcgrath answered 18/3, 2016 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.