H
H
hellcaster2018-08-16 20:16:55
Node.js
hellcaster, 2018-08-16 20:16:55

What does Node.js want from me?

When I run gulpfile (namely gulp html), Node.js says I didn't fulfill some promises
[20:12:49] Starting 'html'...
(node:4548) UnhandledPromiseRejectionWarning: Unhandled promise rejection ( rejection id: 2): [object Object]
(node:4548) [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.

Gulpfile
/***************************************************\
|              Required all plugins                 |
\***************************************************/
const
  del          = require("del"),
  gulp         = require("gulp"),
  webp         = require("gulp-webp"),
  minify       = require("gulp-csso"),
  sass         = require("gulp-sass"),
  rename       = require("gulp-rename"),
  run          = require("run-sequence"),
  plumber      = require("gulp-plumber"),
  postcss      = require("gulp-postcss"),
  csscomb      = require("gulp-csscomb"),
  autoprefixer = require("autoprefixer"),
  posthtml     = require("gulp-posthtml"),
  svgstore     = require("gulp-svgstore"),
  imagemin     = require("gulp-imagemin"),
  imgRetina    = require("gulp-img-retina"),
  include      = require("posthtml-include"),
  resizer      = require("gulp-images-resizer"),
  server       = require("browser-sync").create();

/***************************************************\
|                Plugins settings                   |
\***************************************************/
const retinaOpts = {
  suffix: { 2: '@2x', 3: '@3x' }
};

/***************************************************\
|                    Gulp style                     |
\***************************************************/
gulp.task("style", function() {
  gulp.src("src/sass/style.scss")
    .pipe(plumber())
    .pipe(sass().on("error", sass.logError))
    .pipe(postcss([autoprefixer()]))
    .pipe(csscomb())
    .pipe(gulp.dest("build/css"))
    .pipe(minify())
    .pipe(rename("style.min.css"))
    .pipe(gulp.dest("build/css"))
    .pipe(server.stream());
});

/***************************************************\
|                    Gulp html                      |
\***************************************************/
gulp.task("html", function() {
  return gulp.src("src/*.html")
    .pipe(posthtml([
      include()
    ]))
    .pipe(imgRetina(retinaOpts))
    .pipe(gulp.dest("build"));
});

/***************************************************\
|                    Gulp sprite                     |
\***************************************************/
gulp.task("sprite", function() {
  return gulp.src("src/img/svg/icon-*.svg")
    .pipe(svgstore({
      inlineSvg: true
    }))
    .pipe(rename("sprite.svg"))
    .pipe(gulp.dest("build/img"));
});

/***************************************************\
|               Gulp retina @2x                     |
\***************************************************/
gulp.task("[email protected]", function() {
  return gulp.src("src/img/**/*.{png,jpg,jpeg}")
    .pipe(gulp.dest("build/img"))
    .pipe(resizer({
      width: "200%"
    }))
    .pipe(rename({ suffix: "@2x"}))
    .pipe(gulp.dest("build/img"))
});

/***************************************************\
|               Gulp retina @3x                     |
\***************************************************/
gulp.task("[email protected]", function() {
  return gulp.src("src/img/**/*.{png,jpg,jpeg}")
    .pipe(gulp.dest("build/img"))
    .pipe(resizer({
      width: "300%"
    }))
    .pipe(rename({ suffix: "@3x"}))
    .pipe(gulp.dest("build/img"))
});

/***************************************************\
|               Gulp retina FULL                    |
\***************************************************/
gulp.task("retina", function(done) {
  run (
    "[email protected]",
    "[email protected]",
    done
  )
});

/***************************************************\
|               Gulp convert .webp                  |
\***************************************************/
gulp.task("webp", function() {
  return gulp.src("build/img/**/*.{png,jpg}")
    .pipe(webp({ quality: 90 }))
    .pipe(gulp.dest("build/img"))
});

/***************************************************\
|              Gulp minify img                      |
\***************************************************/
gulp.task("images", function() {
  return gulp.src("src/img/**/*.{png,jpg,svg}")
    .pipe(imagemin([imagemin.optipng({ optimizationLevel: 3 }),
      imagemin.jpegtran({ progressive: true }),
      imagemin.svgo()
    ]))
    .pipe(gulp.dest("src/img"))
});

/***************************************************\
|           Gulp imageFullCycle                     |
\***************************************************/
gulp.task("imageFullCycle", function(done) {
  run (
    "sprite",
    "retina",
    "webp",
    "images",
    done
  )
});

/***************************************************\
|           Gulp copy all to build                  |
\***************************************************/
gulp.task("copy", function() {
  return gulp.src([
      "src/fonts/**/*.{woff,woff2}",
      "src/img/**",
      "src/js/**"
    ], {
      base: "src"
    })
    .pipe(gulp.dest("build"));
});

/***************************************************\
|                 Gulp clean build                  |
\***************************************************/
gulp.task("clean", function() {
  return del("build");
});

/***************************************************\
|                    Gulp BUILD                     |
\***************************************************/
gulp.task("build", function(done) {
  run(
    "clean",
    "copy",
    "style",
    "imageFullCycle",
    "html",
    done
  );
});

/***************************************************\
|                    Gulp SERVER                     |
\***************************************************/
gulp.task("serve", function() {
  server.init({
    server: "build/"
  });

  gulp.watch("src/sass/**/*.scss", ["style"]);
  gulp.watch("src/*.html", ["html"]);
  gulp.watch("src/js/*.js").on("change", server.reload);
});


(I think it's something with an include)
package.json
"scripts": {
    "test": "gulp style",
    "build": "gulp build",
    "start": "npm run build && gulp serve"
  },

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
hellcaster, 2018-08-16
@web_Developer_Victor

The problem was not in gulp or node.js, but in the include paths (you need to specify from the gulpfile.js file, and not from the current file)

I
ixon, 2018-08-16
@ixon

This is just a warning.

Отказ. Предупреждение. Отклонения от необработанных обещаний устарели. В будущем обещание отклонения, которое не обрабатывается, приведет к завершению процесса Node.js с ненулевым кодом выхода.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question