AssertionError при компиляции - PullRequest
0 голосов
/ 06 февраля 2019

Добрый день

Не могли бы вы любезно помочь и посоветовать, в чем заключается проблема, это произошло после того, как я обновлю пакеты npm, NodeJ, Yarn и т. Д. Я знаю, что проблема может бытьоднако в Gulpfile я не могу точно определить его

В основном этот код предназначен для веб-сайта, которым я в настоящее время занят для компании, в которой я работаю.В общем, например, после внесения изменений в содержимое и все изменения встраиваются в папку «tmp», которая теперь используется на веб-сервере для фактического размещения изменений на веб-сайте компании.

Этотакое сообщение об ошибке, с которым я сталкиваюсь на CMD

$ gulp
assert.js:350
throw err;
^

AssertionError [ERR_ASSERTION]: Task function must be specified
at Gulp.set [as _setTask] (C:\Repo\interfront-website\node_modules\undertaker\lib\set-task.js:10:3)
at Gulp.task (C:\Repo\interfront-website\node_modules\undertaker\lib\task.js:13:8)
at Object.<anonymous> (C:\Repo\interfront-website\gulpfile.js:74:6)
  at Module._compile (internal/modules/cjs/loader.js:689:30)
  at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
  at Module.load (internal/modules/cjs/loader.js:599:32)
  at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
  at Function.Module._load (internal/modules/cjs/loader.js:530:3)
  at Module.require (internal/modules/cjs/loader.js:637:17)
  at require (internal/modules/cjs/helpers.js:22:18)
  error Command failed with exit code 1.
  info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Gulpfile.js

 // static server + watching scss/njk files
gulp.task("serve", ["scss"], function() {
  $.browserSync.init({ server: paths.build.base });
  // scss file watcher
  gulp
    .watch(paths.src.scss + "**/*.scss", ["scss"])
    .on("change", function(event) {
      $.fancyLog(
        "File " +
          event.type +
          $.chalk.cyanBright(" scss: ") +
          $.chalk.magentaBright(event.path)
      );
    });
  // njk file watcher
  gulp
    .watch(
      [
        paths.src.njk + "**/*.+(html|njk)",
        paths.src.templates + "**/*.+(html|njk)",
        paths.src.data + "**/*.json"
      ],
      ["njk-watch"]
    )
    .on("change", function(event) {
      $.fancyLog(
        "File " +
          event.type +
          $.chalk.cyanBright(" njk: ") +
          $.chalk.magentaBright(event.path)
      );
    });
});

// scss - build the scss to the build (tmp) folder, including the required paths, and writing out a sourcemap
gulp.task("scss", ["njk"], function() {
  $.fancyLog("Compile: " + $.chalk.greenBright("scss to css."));
  return gulp
    .src(paths.src.scss + vars.scssName)
    .pipe($.plumber({ errorHandler: onError }))
    .pipe($.sourcemaps.init({ loadMaps: true }))
    .pipe($.sass().on("error", $.sass.logError))
    .pipe($.autoprefixer({ browsers: ["last 2 versions", "> 5%"] }))
    .pipe($.cleanCss({ compatibility: "ie9" }))
    .pipe($.header(banner, { pkg: pkg }))
    .pipe($.sourcemaps.write("./"))
    .pipe(gulp.dest(paths.build.css))
    .pipe($.browserSync.stream());
});

var manageEnvironment = function(environment) {
  environment.addFilter('is_array', function(obj) {
    return obj && Array.isArray(obj);
  });

  environment.addGlobal('globalTitle', 'My global title')
}

// njk - build the nunjucks templates to the build (tmp) folder as html files
gulp.task("njk", function() {
  $.fancyLog("Compile: " + $.chalk.greenBright("njk to html."));
  return gulp
    .src(paths.src.njk + "**/*.+(html|njk)")
    .pipe($.plumber({ errorHandler: onError }))
    .pipe($.data(getDataForFile("procurement.json")))
    .pipe($.data(getDataForFile("careers.json")))
    .pipe($.data(getDataForFile("sitemap.json")))
    .pipe($.nunjucksRender({
      path: ["src/templates/"],
      manageEnv: manageEnvironment
    }))
    .pipe(gulp.dest(paths.build.base));
});

// njk-watch - ensures the `njk` task is complete before reloading browsers
gulp.task("njk-watch", ["njk"], function(done) {
  $.browserSync.reload();
  done();
});

// js - lint, minify and copy js files to (tmp) folder
gulp.task("js", function() {
  $.fancyLog("Process: " + $.chalk.greenBright("js."));
  return gulp
    .src(paths.src.js + "**/*.js")
    .pipe($.plumber({ errorHandler: onError }))
    .pipe($.sourcemaps.init())
    .pipe($.uglify())
    .pipe($.sourcemaps.write("./maps"))
    .pipe(gulp.dest(paths.build.js));
});

// Copy assets
gulp.task("assets", function() {
  return gulp
    .src([paths.src.assets + "**/*.*", paths.src.assets + "**/.*"])
    .pipe(gulp.dest(paths.build.assets));
});

// Copy Docs
gulp.task("docs", function() {
  return gulp.src(paths.src.docs + "**/*.*").pipe(gulp.dest(paths.build.docs));
});

// service worker
gulp.task("bundle-sw", ["serve"], function() {
  return $.workboxBuild
    .generateSW({
      globDirectory: paths.build.base,
      swDest: paths.build.base + "sw.js",
      globPatterns: ["**/*.{html,js,css}"],
      globIgnores: ["admin.html"]
    })
    .then(() => {
      console.log("Service worker generated.");
    })
    .catch(err => {
      console.log("[ERROR] This happened: " + err);
    });
});

// default serve (runs on yarn start)
gulp.task("default", ["serve", "assets", "docs"]);

// production build (runs on yarn build)
gulp.task("build", ["bundle-sw"]);

// run all tests
const exec = require("child_process").exec;

gulp.task("test", ["default"], function() {
  exec("npm run test-all");
});
...