首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自svg-sprite的带有svg2png的UnhandledPromiseRejectionWarning

来自svg-sprite的带有svg2png的UnhandledPromiseRejectionWarning
EN

Stack Overflow用户
提问于 2018-03-20 14:34:13
回答 2查看 673关注 0票数 1

我有一个svg2png的问题,我想把我的svg文件转换成png,它在gulp任务中说它是UnhandledPromiseRejectionWarning

代码语言:javascript
复制
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']);

当我在我的命令行上运行它时,它会说

代码语言:javascript
复制
(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.
EN

回答 2

Stack Overflow用户

发布于 2018-03-20 14:42:24

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

代码语言:javascript
复制
gulp.task('icons', ['beginClean', 'createSprite', 'createPngCopy', 'copySpriteGraphic', 'copySpriteCSS', 'endClean'], function() {
   return true; 
});
票数 0
EN

Stack Overflow用户

发布于 2019-02-09 09:48:22

首先,让我向您提供我正在使用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安装

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49377675

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档