I am new to nodejs and gulp stuff. I working on a nodejs project in which I have to run jslint on all the files. I am using gulp for this purpose.
My problem is that In order to run gulp on cli I don't want to install gulp globally and also does not want to update my path variable, So I have installed gulp and other node modules in my project locally using the package.json file
cd myproject
npm install
Since I don't want to install gulp globally and want to run the local gulp I have added script in my package.json file like this as given in this question
{ "name": "", "version": "1.0.0", "main": "index.js", "private": true, "dependencies": { "async": "1.5.0" }, "devDependencies": { "gulp": "^3.9.0", "gulp-jslint": "^0.2.2" }, "scripts": { "gulp": "./node_modules/.bin/gulp" // is this correct? } }
Add added a gulpfile.js inside my myproject folder
var gulp = require('gulp'); // include plug-ins var jslint = require('gulp-jslint'); // JS hint task gulp.task('lint', function() { gulp.src('./common/srp/*.js') .pipe(jslint()) .pipe(jslint.reporter('default')); }); gulp.task("default", ["lint"]);
But now on my command line inside myproject folder, when I run gulp and gulp lint I get an error
user1-VirtualBox:~/myproject$ gulp lint
/usr/local/node-v0.10.26-linux-x64/bin/gulp No such file or directory
Its looking for gulp in the global node module.
Is there a way to make gulp run on cli without installing globally and updating PATH variable.
Any help will be appreciated Thanks
Install Gulp into your local project To install Gulp locally, navigate to your project directory and run npm install gulp . You can save it to your package. json dependencies by running npm install gulp --save-dev . Once you have Gulp installed locally, you can then proceed to create your gulpfile.
To solve the error "'gulp' is not recognized as an internal or external command, operable program or batch file", install the gulp-cli package globally by running npm install -g gulp-cli , restart your terminal and make sure your PATH environment variable is set up correctly.
First run npm -g install gulp-cli then run gulp -v. Alternatively, you can just run npm list gulp.
To solve the error "gulp: command not found", install the gulp-cli package globally by running npm install -g gulp-cli and restart your terminal. If the command fails, run it with sudo and make sure the correct PATH is set in your system's environment variable.
You can find any executable installed by npm in node_modules/.bin
. So you can run gulp locally using:
./node_modules/.bin/gulp
You can find more information at no command 'gulp' found - after installation
With your code you should be able to run command npm run gulp
Please try
One way to define script is
"scripts": { "gulp": "gulp" }
If in case you are not able to run gulp command in your project, run
npm link gulp
It will link your global install gulp with your local project. Then try
gulp -v
If it is showing you the version then you are done. Now you can run any gulp command as you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With