Reputation: 1114
I have created a demo using GULP, but facing issues to run the gulp js file.
Process of installing:
sudo npm init
sudo npm install gulp-jshint gulp-sass gulp-concat gulp-uglify gulp-rename --save-dev
sudo npm install --save-dev gulp
Console Warn:
mnbcvd3456:glp user$ sudo npm install gulp
npm WARN package.json [email protected] No repository field.
npm WARN install Refusing to install gulp as a dependency of itself
package.JSON:
{
"name": "gulp",
"version": "3.8.6",
"description": "Gulp Demo",
"main": "index.js",
"directories": {
"doc": "doc"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "User",
"license": "ISC",
"devDependencies": {
"gulp-concat": "^2.3.3",
"gulp-jshint": "^1.7.1",
"gulp-rename": "^1.2.0",
"gulp-sass": "^0.7.2",
"gulp-uglify": "^0.3.1"
}
}
Gulp.js file.
// Include gulp
var gulp = require('gulp');
// Include Our Plugins
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
// Lint Task
gulp.task('lint', function() {
return gulp.src('js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Concatenate & Minify JS
gulp.task('scripts', function() {
return gulp.src('js/*.js')
.pipe(concat('all.js'))
.pipe(gulp.dest('dist'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('dist'));
});
// Watch Files For Changes
gulp.task('watch', function() {
gulp.watch('js/*.js', ['lint', 'scripts']);
});
// Default Task
gulp.task('default', ['lint', 'scripts', 'watch']);
Now If am trying to run my gulp js file, using the command "gulp". then its thowing an error as:
mnbcvd3456:glp user$ gulp
module.js:340
throw err;
^
Error: Cannot find module 'gulp'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/Users/glp/gulpfile.js:5:12)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
Upvotes: 3
Views: 14562
Reputation: 39
The problem is that you named the "name" "gulp".
Change your "name" to anything you like but "gulp".
You can also see this: https://github.com/npm/npm/issues/13898
Upvotes: 2
Reputation: 9084
I think the problem might mbe that you have both installations on the same level. So both grunt and gulp try to access pakage.json.
Try to install them in different folders.
Also, install gulp globally, then locally on a different folder than grunt, create an empty package like this:
{
"name": "name_you_want",
"version": "0.0.1",
"devDependencies": { }
}
and add plugins for dev like this (command line over folder where your package.json is: npm install --save-dev plugin_name
Plus: why will you use both grunt & gulp ?
Upvotes: 0