我使用gulp任务来缩小css和js文件,但是每次打开gulp时都会得到这个错误。我找出了任何解决办法,但仍未解出问题。
任务:命令失败: gulp -任务--简单--cwd "c:\wamp64\www\gulp_p“--gulpfile (c:\wamp64\www\gulp_p\node_modules\undertaker\lib\task.js:13:8) assert.js:374抛出错误;^ AssertionError ERR_ASSERTION:任务函数必须在对象处的Gulp.task as _setTask指定。(c:\wamp64\www\gulp_p\gulpfile.js:64:6) Module._compile (内部/模块/cjs/loader.js:956:30),Object.Module._extensions..js (内部/模块/cjs/loader.js:973:10),Module.load (内部/模块/cjs/loader.js:812:32),Function.Module._load (内部/模块/cjs/loader.js:724:14)在execute (C:\Users\alia\AppData\Roaming\npm\node_modules\gulp-cli\lib\versioned\^4.0.0\index.js:36:18) { generatedMessage: false ( Module.require /generatedMessage/cjs/helpers.js:74:18)时,在Module.require(内部/模块/cjs/loader.js:849:19)代码:‘ERR_断言’,实际: false,预期: true,操作符:'==‘}
我的安装
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.0package.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正在工作,因为我正在不同的计算机上使用它。所以gulpfile.js没有错误,它位于项目的根目录
'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']);发布于 2019-11-07 15:22:20
由于您使用的是gulp v4,此代码将无法工作:
gulp.task('default',['choose','css','scripts']);
将其改为:
gulp.task('default',gulp.series('choose','css','scripts'));
此操作的另一台计算机必须使用gulp v3。
https://stackoverflow.com/questions/58709290
复制相似问题