jackfranklin / gulp-load-plugins

Automatically load in gulp plugins
https://github.com/jackfranklin/gulp-load-plugins
MIT License
757 stars 55 forks source link

dependencies cannot be required from NODE_PATH #71

Closed rmorlang closed 9 years ago

rmorlang commented 9 years ago

The application I'm working on is being integrated into a build environment that requires that all external dependencies live in a separate directory hierarchy. So this means I've had to move node_modules from the root directory of my application into a path like /home/user/libraries/node_modules. Generally this means just setting the NODE_PATH environment variable to $NODE_PATH:/home/user/libraries/node_modules. This works fine for loading gulp, but it breaks with gulp-load-plugins.

This seems to be a result of the changes introduced in 05bc2845, which addresses issues #56 and #57. gulp-load-plugins searches up through the directory hierarchy to try to find plugins, but if no matching plugin path is found findup() returns null, and so gulp-load-plugins ends up invoking require(null), resulting in the following error:

AssertionError: path must be a string
    at Module.require (module.js:362:3)
    at require (module.js:380:17)
    at requireFn (/home/user/work/libraries/node_modules/gulp-load-plugins/index.js:38:14)
    at Object.defineProperty.get (/home/user/work/libraries/node_modules/gulp-load-plugins/index.js:75:18)
    at module.exports (/home/user/work/application/gulp/e2e-tests.js:11:34)
    at guesspath (/home/user/work/application/gulpfile.js:25:30)
    at Array.map (native)
    at Object.<anonymous> (/home/user/work/application/gulpfile.js:24:6)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

I have a PR in progress.

jackfranklin commented 9 years ago

@rleemorlang I think that V0.10 will solve this if I've understood. If it doesn't please reopen.

eborden commented 8 years ago

I'm still seeing this issue. I'm using 1.1.0.

jackfranklin commented 8 years ago

@eborden going to need some more info - can you get a repo that replicates this issue up for us to take a look at? Do you see the exact same error as above? A stack trace would be useful.

eborden commented 8 years ago

The error is slightly different. My guess is that this is actually a problem with resolve not correctly handling $NODE_PATH. When using require these plugins load perfectly, but fail with gulp-load-plugins.

/nix/store/c4fa8kybxzfbr6x1fpxm25wmxz5kcq7r-narsDeps/node_modules/resolve/lib/sync.js:33
    throw new Error("Cannot find module '" + x + "' from '" + y + "'");
    ^

Error: Cannot find module 'gulp-cli' from '/home/eborden/skedge/skedge/widgets/nars'
    at Function.module.exports [as sync] (/nix/store/c4fa8kybxzfbr6x1fpxm25wmxz5kcq7r-narsDeps/node_modules/resolve/lib/sync.js:33:11)
    at requireFn (/nix/store/c4fa8kybxzfbr6x1fpxm25wmxz5kcq7r-narsDeps/node_modules/gulp-load-plugins/index.js:46:25)
    at defineProperty (/nix/store/c4fa8kybxzfbr6x1fpxm25wmxz5kcq7r-narsDeps/node_modules/gulp-load-plugins/index.js:89:29)
    at /nix/store/c4fa8kybxzfbr6x1fpxm25wmxz5kcq7r-narsDeps/node_modules/gulp-load-plugins/index.js:120:7
    at Array.forEach (native)
    at module.exports (/nix/store/c4fa8kybxzfbr6x1fpxm25wmxz5kcq7r-narsDeps/node_modules/gulp-load-plugins/index.js:110:30)
    at Object.<anonymous> (/home/eborden/skedge/skedge/widgets/nars/gulpfile.js:12:51)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
eborden commented 8 years ago

It'll take a little more effort for me to create a repo to reproduce this, but I'll see if I can get to it today.

jackfranklin commented 8 years ago

@eborden perfect, thank you. Might be a bug in resolve but happy to do digging if you can get a repo, thanks :)

Chrisedmo commented 7 years ago

Any updates on this ? Where did it get up to? I'm getting a similar error…

jackfranklin commented 7 years ago

@Chrisedmo I have never had this error + have not been able to replicate. I also don't work on this project much or use Gulp these days. I'm afraid I need some help with this. If people can give me a Github repo that shows the issue easily I might be able to dig into it, or if someone else can figure it and make a PR that's great, I'd love to merge it, but the chances of me fixing it soon are slim to none.