问题
Ive got a problem with svg2png, i want to convert my svg file to png and it says in gulp task that it's UnhandledPromiseRejectionWarning
var gulp = require('gulp'),
svgSprite = require('gulp-svg-sprite'),
rename = require('gulp-rename'),
del = require('del'),
svg2png = require('gulp-svg2png');
// var config consist of mode we used, and it used the css mode
var config = {
mode: {
css: {
sprite: 'sprite.svg',
render: {
css: {
template: './gulp/template/sprite.css'
}
}
}
}
}
gulp.task('beginClean', function() {
return del(['./app/temp/sprite', './app/assets/images/sprites']);
});
gulp.task('createSprite', ['beginClean'], function() {
return gulp.src('./app/assets/images/icons/**/*.svg')
.pipe(svgSprite(config))
.pipe(gulp.dest("./app/temp/sprite/"));
});
gulp.task('createPngCopy', ['createSprite'], function() {
return gulp.src('./app/temp/sprite/css/*.svg')
.pipe(svg2png())
.pipe(gulp.dest('./app/temp/sprite/css'));
});
gulp.task('copySpriteGraphic', ['createPngCopy'], function() {
return gulp.src('./app/temp/sprite/css/**/*.{svg,png}')
.pipe(gulp.dest('./app/assets/images/sprites'));
});
gulp.task('copySpriteCSS', ['createSprite'], function() {
return gulp.src('./app/temp/sprite/css/*.css')
.pipe(rename('_sprite.css'))
.pipe(gulp.dest('./app/assets/styles/modules'));
});
gulp.task('endClean', ['copySpriteGraphic', 'copySpriteCSS'], function() {
return del('./app/temp/sprite');
});
gulp.task('icons', ['beginClean', 'createSprite', 'createPngCopy', 'copySpriteGraphic', 'copySpriteCSS', 'endClean']);
and when i run it on my command line "gulp icons" it says
(node:8400) UnhandledPromiseRejectionWarning
(node:8400) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:8400) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
回答1:
I think this is because of last line of code. you need to handle the call back for last task as well to remove this warning.
gulp.task('icons', ['beginClean', 'createSprite', 'createPngCopy', 'copySpriteGraphic', 'copySpriteCSS', 'endClean'], function() {
return true;
});
回答2:
Let me begin by providing you with the versions of the packages i am using
Node = 8.12.0
Npm = 6.41
Gulp Local = 3.9.1
Gulp CLI = 2.0.1
The version of the Svg2png I was using is 2.0.2, My solution was as follows
uninstall Svg2Png npm uninstall gulp-svg2png --save-dev
and then install it using npm install gulp-svg2png@1.0.0 --save-dev
来源:https://stackoverflow.com/questions/49377675/unhandledpromiserejectionwarning-with-svg2png-from-svg-sprite