本文介绍了来自svg-sprite的svg2png的UnhandledPromiseRejectionWarning的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

svg2png出现问题,我想将svg文件转换为png,并且在gulp任务中说这是UnhandledPromiseRejectionWarning

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']);

当我在命令行"gulp图标"上运行它时,它说

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.

推荐答案

首先让我向您提供我正在使用的软件包的版本 Node = 8.12.0 Npm = 6.41 Gulp Local = 3.9.1 Gulp CLI = 2.0.1

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

我使用的Svg2png版本是2.0.2,我的解决方法如下卸载Svg2Png npm uninstall gulp-svg2png --save-dev,然后使用npm install [email protected] --save-dev

The version of the Svg2png I was using is 2.0.2, My solution was as followsuninstall Svg2Png npm uninstall gulp-svg2png --save-dev and then install it using npm install [email protected] --save-dev

这篇关于来自svg-sprite的svg2png的UnhandledPromiseRejectionWarning的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-25 05:22