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

node.jsNpmGulp

node.js Problem Overview


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?

node.js Solutions


Solution 1 - node.js

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

Solution 2 - node.js

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

npm install

Solution 3 - node.js

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.

Solution 4 - node.js

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

Solution 5 - node.js

Try to install the missing module.

npm install 'module-name'

Solution 6 - node.js

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

Solution 7 - node.js

This will solve all gulp problem

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

Solution 8 - node.js

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.

Solution 9 - node.js

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.

Solution 10 - node.js

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.

Solution 11 - node.js

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionNicolas Le Thierry d'EnnequinView Question on Stackoverflow
Solution 1 - node.jsIlan FrumerView Answer on Stackoverflow
Solution 2 - node.jsnumediawebView Answer on Stackoverflow
Solution 3 - node.jsfrostmanView Answer on Stackoverflow
Solution 4 - node.jsC-Note187View Answer on Stackoverflow
Solution 5 - node.jsxatzView Answer on Stackoverflow
Solution 6 - node.jsNikita JajodiaView Answer on Stackoverflow
Solution 7 - node.jskedar kokilView Answer on Stackoverflow
Solution 8 - node.jsMother10View Answer on Stackoverflow
Solution 9 - node.jsBalram SinghView Answer on Stackoverflow
Solution 10 - node.jsInigoView Answer on Stackoverflow
Solution 11 - node.jsNayanView Answer on Stackoverflow