0
votes

I use gulp tasks to minify css and js files, but I get this error each time I open the gulp. I searched for any solution but still not figured out the problem.

Gulp Tasks: Command failed: gulp --tasks-simple --cwd "c:\wamp64\www\gulp_p" --gulpfile "c:\wamp64\www\gulp_p\gulpfile.js" assert.js:374 throw err; ^ AssertionError [ERR_ASSERTION]: Task function must be specified at Gulp.set [as _setTask] (c:\wamp64\www\gulp_p\node_modules\undertaker\lib\set-task.js:10:3) at Gulp.task (c:\wamp64\www\gulp_p\node_modules\undertaker\lib\task.js:13:8) at Object. (c:\wamp64\www\gulp_p\gulpfile.js:64:6) at Module._compile (internal/modules/cjs/loader.js:956:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:973:10) at Module.load (internal/modules/cjs/loader.js:812:32) at Function.Module._load (internal/modules/cjs/loader.js:724:14) at Module.require (internal/modules/cjs/loader.js:849:19) at require (internal/modules/cjs/helpers.js:74:18) at execute (C:\Users\alia\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0\index.js:36:18) { generatedMessage: false, code: 'ERR_ASSERTION', actual: false, expected: true, operator: '==' }

my installation

gulp --version => CLI version: 2.2.0  -  Local version: 4.0.2
node --version => v12.13.0
npm --version => 6.12.0
npx --version => 6.12.0

package.json

{
  "name": "gulp_p",
  "version": "1.0.0",
  "main": "gulpfile.js",
  "dependencies": {
    "gulp": "^4.0.2",
    "gulp-clean": "^0.4.0",
    "gulp-clean-css": "^3.10.0",
    "gulp-concat": "^2.6.1",
    "gulp-concat-css": "^3.1.0",
    "gulp-inject": "^4.3.2",
    "gulp-install": "^1.1.0",
    "gulp-minify": "^3.1.0",
    "gulp-minify-css": "^1.2.4",
    "gulp-prompt": "^1.1.0",
    "gulp-requirejs": "^1.2.0",
    "gulp-watch": "^5.0.1"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": ""
}

gulpfiles.js is working as I am using it on different computer. So there's no error with the gulpfile.js and it is located at the root of the project

'use strict';

var gulp = require('gulp');

var prompt = require('gulp-prompt');
var log = require('fancy-log');
var concatCss = require('gulp-concat-css');
var minifyCSS = require('gulp-minify-css');
var cleanCSS = require('gulp-clean-css');

var concat = require('gulp-concat');
var minify = require('gulp-minify');
var clean = require('gulp-clean');

var watch = require('gulp-watch');

var theme_input='sunstar';

gulp.task('css', function() {
    var importFrom = require('gulp/themes/'+theme_input+'.js');
    return gulp.src(importFrom.css_arr,{base: '.'})
      .pipe(concatCss(importFrom.destination_css))
      .pipe(minifyCSS({keepSpecialComments: 0}))
      .pipe(gulp.dest('.'));
  });

gulp.task('scripts', function() {
    var importFrom = require('gulp/themes/'+theme_input+'.js');
    return gulp.src(importFrom.js_arr)
      .pipe(concat(importFrom.destination_js))
      .pipe(minify({keepSpecialComments: 0}))
      .pipe(gulp.dest('.'));
  });


gulp.task('choose', function(){
    log('Please enter THEME name, then type of task [js/css].');
    return gulp.src('*')
    .pipe(prompt.prompt([{
        type: 'input',
        name: 'theme_input',
        message: 'Please enter THEME name?'
    },{
        type: 'input',
        name: 'task',
        message: 'Please enter task Type?'
    }], function(res){
        theme_input = res.theme_input;
        var importFrom = require('gulp/themes/'+theme_input+'.js');
        if(res.task == 'css'){
            gulp.src(importFrom.css_arr,{base: '.'})
            .pipe(concatCss(importFrom.destination_css))
            .pipe(minifyCSS({keepSpecialComments: 0}))
            .pipe(gulp.dest('.'));
        }else if(res.task == 'js'){
            gulp.src(importFrom.js_arr)
            .pipe(concat(importFrom.destination_js))
            .pipe(minify({keepSpecialComments: 0}))
            .pipe(gulp.dest('.'));
        }
    }));
});

gulp.task('default',['choose','css','scripts']);
1
Nevertheless, since that is a common gulpfile.js error you should include your gulpfile if you want help.Mark
@Mark of course as i am still stuck on this errorAli Al Amine

1 Answers

4
votes

Since you are using gulp v4 this code will not work:

gulp.task('default',['choose','css','scripts']);

Change that to:

gulp.task('default',gulp.series('choose','css','scripts'));

The other computer that this works on must be using gulp v3.