![](/img/trans.png)
[英]Plumber, notify and a custom error fucntion give me an Error in plugin 'plumber': Message: Can't pipe to undefined
[英]Gulp plumber cannot pipe to undefined
我正在嘗試編寫一個模塊,當gulp正在監視任務時,並且Less文件因某些錯誤而更改時,它應該向控制台發送一條消息,但不應使系統崩潰,它不會這樣做:我寫的代碼:
var onError = function (err) {
console.log(err);
};
gulp.task('styles', function () {
gulp.src('./{views}/**/*.{less}')
.pipe(plumber({
errorHandler: onError
}))
.pipe(less())
.pipe(gulp.dest('build/styles/common.css'));
});
當我運行上面的代碼時,出現以下錯誤:
'styles' errored after 20 ms
Error in plugin 'plumber'
Message:
Can't pipe to undefined
我有同樣的錯誤。 我通過在管道工之后添加()來解決該問題。 這是代碼。
較早的代碼:
gulp.task('scripts',function(){
gulp.src('admin-scripts.js')
.pipe(plumber)
.pipe(uglify().on('error', function(e){
console.log(e);
}))
.pipe(gulp.dest('build/js'));
});
固定代碼:
gulp.task('scripts',function(){
gulp.src('admin-scripts.js')
.pipe(plumber())
.pipe(uglify().on('error', function(e){
console.log(e);
}))
.pipe(gulp.dest('build/js'));
});
水管工后我錯過了()。 希望這可以幫助。
您確定已安裝了無gulp使用
npm install --save-dev
並在您的gulpfile中引用它
var less = require('gulp-less');
當管道的目標位置(此處為less )未定義時,就會發生來自管道工的錯誤。
另外,為什么在這里使用{}
? 我認為它們有點無用,因為您只針對其中的一件事,所以可以將其刪除。
是的,我已經安裝了無gulp的軟件,並且我也找到了解決此問題的解決方案:應該如下所示:
gulp.task('mystyle', function () {
gulp.src('build/stylesfiles.less').pipe(plumber()).pipe(less()).
pipe(gulp.dest ('build/styles/assets'));
});
基本上我不需要錯誤消息,它會給我一個默認錯誤,可以完成我的工作。使用上面的代碼將確保它運行,並給我我的錯誤,但不會使服務器崩潰....但是謝謝你“ Apercu”
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.