Reputation: 7330
From the instructions page of gulp, it's asked to install it globally as well as in the project as dev dependency.
My question is why do we need to install it twice? Why can't the project one use the global one?
and I do get this error prompting to install it locally and I've followed this tutorial as well but still stuck. http://blog.webbb.be/command-not-found-node-npm/
[11:47:51] Local gulp not found in ~/Documents/project
[11:47:51] Try running: npm install gulp
Link-> https://github.com/gulpjs/gulp/blob/master/docs/getting-started.md
Upvotes: 4
Views: 1698
Reputation: 96889
The error means you didn't install gulp
locally. This means you have to add it to your dependencies in package.json
(or just call npm i gulp --save
).
It needs to be installed locally because gulpfile.js
typically runs some code related to gulp
. That's why it calls var gulp = require('gulp');
at the top of your gulpfile.js
. This call loads gulp
from your package node_modules
. That's also where functions like gulp.task
or gulp.src
come from.
At the same you want to easily use gulp
in CLI, that's why it needs to be installed also globally so you can run it by just:
$ gulp
Btw, you can also run just your local gulp
:
Insert to your package.json
:
"scripts": {
"gulp": "gulp",
}
This tells npm
that by executing gulp
command we want to run script ./node_modules/.bin/gulp
.
Run (you'd have to do this in all projects):
$ npm run gulp
So it's definitely easier to install it globally.
Upvotes: 2