Can't get Gulp to run: cannot find module '

2019-01-10 02:08发布

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 npm gulp
8条回答
够拽才男人
2楼-- · 2019-01-10 02:46

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.

查看更多
不美不萌又怎样
3楼-- · 2019-01-10 02:48

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

npm install
查看更多
再贱就再见
4楼-- · 2019-01-10 02:52

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

查看更多
趁早两清
5楼-- · 2019-01-10 02:52

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
查看更多
手持菜刀,她持情操
6楼-- · 2019-01-10 02:57

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')
查看更多
劫难
7楼-- · 2019-01-10 03:05

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.

查看更多
登录 后发表回答