【问题标题】:UnhandledPromiseRejectionWarning with svg2png from svg-spriteUnhandledPromiseRejectionWarning 来自 svg-sprite 的 svg2png
【发布时间】:2018-03-20 06:34:13
【问题描述】:

我遇到了 svg2png 的问题,我想将我的 svg 文件转换为 png,它在 gulp 任务中说它是 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 icons”上运行它时,它会说

(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.

【问题讨论】:

    标签: javascript node.js gulp


    【解决方案1】:

    我认为这是因为最后一行代码。您还需要处理最后一个任务的回调以删除此警告。

    gulp.task('icons', ['beginClean', 'createSprite', 'createPngCopy', 'copySpriteGraphic', 'copySpriteCSS', 'endClean'], function() {
       return true; 
    });
    

    【讨论】:

      【解决方案2】:

      首先让我向您提供我正在使用的软件包的版本 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 gulp-svg2png@1.0.0 --save-dev 安装它

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-06-15
        • 2014-03-29
        • 1970-01-01
        • 2021-10-16
        • 2014-02-13
        • 2020-02-19
        • 1970-01-01
        • 2020-03-03
        相关资源
        最近更新 更多