Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gulp Package JSON

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)
like image 277
user1853128 Avatar asked Feb 20 '26 23:02

user1853128


1 Answers

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

like image 89
GuoxUnqiue Avatar answered Feb 24 '26 15:02

GuoxUnqiue



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!