gulpjs / gulp

A toolkit to automate & enhance your workflow
https://gulpjs.com
MIT License
32.98k stars 4.23k forks source link

Error: Cannot find module 'gulp' #1135

Closed klierik closed 9 years ago

klierik commented 9 years ago

Good day.

I have problem with gulp + gulpfile as symlink :(

Project folder:

$ ls -la
total 1368
drwxr-x---@ 33 aleksej  staff    1122 Jul  3 19:08 .
drwxr-xr-x   9 aleksej  staff     306 Jul  3 19:08 ..
-rw-r-----@  1 aleksej  staff    5667 Apr 28 14:03 .htaccess
-rw-r-----@  1 aleksej  staff    4568 Apr 28 14:03 .htaccess.sample
...
lrwxr-xr-x   1 aleksej  staff      47 Jul  3 19:08 gulpfile.js -> ../vendor/mavenecommerce/mbootstrap/gulpfile.js
drwxr-xr-x  17 aleksej  staff     578 Jul  3 19:09 node_modules
lrwxr-xr-x   1 aleksej  staff      48 Jul  3 19:08 package.json -> ../vendor/mavenecommerce/mbootstrap/package.json
...

So let`s check modules:

$ npm list --depth=0
mbootstrap@1.0.0 /Volumes/LaCie/http/htdocs/mbootstrap.composer/magento
├── del@1.2.0
├── gulp@3.9.0
├── gulp-autoprefixer@2.3.1
├── gulp-bless@3.0.1
├── gulp-cache@0.2.10
├── gulp-concat@2.6.0
├── gulp-imagemin@2.3.0
├── gulp-load-plugins@0.10.0
├── gulp-minify-css@1.2.0
├── gulp-rename@1.2.2
├── gulp-sass@1.3.3
├── gulp-sourcemaps@1.5.2
├── gulp-uglify@1.2.0
└── vinyl-paths@1.0.0

Let`s run gulp:

$ gulp
module.js:338
    throw err;
          ^
Error: Cannot find module 'gulp'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Volumes/LaCie/http/htdocs/mbootstrap.composer/vendor/mavenecommerce/mbootstrap/gulpfile.js:13:12)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

In gulpfile.js on row 13: var gulp = require('gulp');

I don`t understand where is the problem... :(

Maybe anyone can see some problem that i don`t see... ?!

Thaks

callumacrae commented 9 years ago

Have you globally installed it too?

$ npm install -g gulp
klierik commented 9 years ago

Yes, i am:

$ cd && gulp -v
[12:11:03] CLI version 3.8.11
yocontra commented 9 years ago

Your gulpfile is wayyy too deep and your node_modules are way too high up the tree. node only looks up a few directories for node_modules before saying it couldn't find it. Look at the npm/node docs for more info, but it needs to be closer.

klierik commented 9 years ago

Oh, i understand what you mean. You are wright. Thanks a loooot!

wodny commented 8 years ago

Your gulpfile is wayyy too deep and your node_modules are way too high up the tree. node only looks up a few directories for node_modules before saying it couldn't find it. Look at the npm/node docs for more info, but it needs to be closer.

I don't think it's true.

$ pwd
/tmp/dir-test/15/14/13/12/11/10/9/8/7/6/5/4/3/2/1/0
$ ls
gulpfile.js
$ strace -e file gulp |& grep gulp.js
readlink("/srv/pyramid/smms-client-nosite/lib/node_modules/.bin/gulp", "../gulp/bin/gulp.js", 4096) = 19
lstat("/srv/pyramid/smms-client-nosite/lib/node_modules/gulp/bin/gulp.js", {st_mode=S_IFREG|0755, st_size=5384, ...}) = 0
open("/srv/pyramid/smms-client-nosite/lib/node_modules/gulp/bin/gulp.js", O_RDONLY|O_CLOEXEC) = 9
stat("/tmp/dir-test/15/14/13/12/11/10/9/8/7/6/5/4/3/2/1/0/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/10/9/8/7/6/5/4/3/2/1/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/10/9/8/7/6/5/4/3/2/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/10/9/8/7/6/5/4/3/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/10/9/8/7/6/5/4/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/10/9/8/7/6/5/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/10/9/8/7/6/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/10/9/8/7/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/10/9/8/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/10/9/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/10/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/11/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/12/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/13/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/14/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/15/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/dir-test/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/tmp/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)
stat("/node_modules/gulp.js", 0x7ffc49012d20) = -1 ENOENT (No such file or directory)

I get the same result for 100 subdirectories.

Don't you think it's a security risk to search for node_modules in upper directories (infinite or arbitrary number of levels)?

yocontra commented 8 years ago

@wodny This is behavior in node, not something that we did - if you feel like this is a problem you should open an issue with the node.js team about it

wodny commented 8 years ago

@contra I see. Thank you for the information.

ShawnJ013 commented 7 years ago

I am learning about gulp and trying to follow some instructions on how to get gulpfile to read, instead of no file found...I am currently getting this error:

C:\dev\vstda>gulp module.js:457 throw err; ^

Error: Cannot find module 'gulpfile.js' at Function.Module._resolveFilename (module.js:455:15) at Function.Module._load (module.js:403:25) at Module.require (module.js:483:17) at require (internal/module.js:20:19) at Liftoff.handleArguments

I don't understand where the problem is coming from?

gparsloe commented 7 years ago

Re-installing at a higher level worked for me. I'm not sure which was important to run, but I ran both $sudo npm install -g gulp@latest and $sudo npm install -g npm@latest, then $ionic serve finally stopped saying that gulp module was missing.

yanchifeng commented 5 years ago

It seem is npm's problem.I couldn't find the file in the dictionary of gulp.But I want to know how to solve this problem.Install the latest gulp version?

schagani commented 4 years ago

I tried "npm update" command and it worked

reinisd17 commented 3 years ago

Hi, i had the same problem only i was trying to use gulp awtch and it couldnt finde the moduels. Luckuly i fixed it. My problem for this was that i had multiple files with the name gulp, so when i tried to use gulp watch this happened:

internal/modules/cjs/loader.js:883 throw err; ^

Error: Cannot find module 'gulp-cli' Require stack:

when i used the "npm install --global gulp-cli" command in the terminal it showed me errors that sed that i all ready have files called gulp and told me all of the locations of the, so i deleted all of them and then ran the command again npm install --global gulp-cli and it works now. I hope this helps somebody.