20

I have gulpfile.js in one directory and node_modules in another. When I run gulp, i get the error - 'Local gulp not found in '..(the directory).. Try running: npm install gulp'

The thing is - I cannot install gulp in the directory of gulpfile.js and so I need a way to tell the gulp to refere to the other directory i have gulp installed in.

4 Answers 4

34

You don't need to install gulp globally if you don't want to. What you can do is run your gulp executable (from your node_modules) and then pass in the location of your gulpfile using the --gulpfile parameter. Also, if you want to control where your gulp is running, make use of the --cwd parameter.

Here's an example:

 <NODE_MODULES DIR>/gulp/bin/gulp.js --gulpfile <GULP FILE> --cwd <SOME DIR>
1
  • I'm using any of these command on Windows and work very well. Thank you. gulp --gulpfile "D:\path\to\gulpfile.js" --tasks, or gulp --cwd "D:\path\to-where-contain-gulpfile-js" --tasks.
    – vee
    Commented Jun 22, 2022 at 16:24
5

There is no need to install gulp globally. First install gulp (ideally on dev dependencies)

npm install gulp --save-dev

Then in the package.json add the line you want to run

"scripts" : { "gulp" : "gulp"} }

Finally in the command line use

npm run gulp

npm will use the binary from the node modules without any need to install it globally or to write down the whole path

3

You need to install gulp globally:

npm install -g gulp

This will allow you to run gulp from the command line in any directory.

1
  • 2
    You never need to install anything globally. You can either write NPM scripts as mentioned above, which will put local cli tools on the path, or make utility aliases such as alias gulp='$(npm bin)/gulp'
    – oligofren
    Commented Feb 8, 2017 at 15:41
0

Put the node_modules folder in parent directory always, then make project directory as child/grandchild folder.

Don't put the node_modules folder in any child directory

Folder structure will be like:

parent

└──node_modules

└─project_1

└─project_2

In any child/grand child directory gulp will work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.