编译时出现AssertionError

时间:2019-02-06 08:31:02

标签: npm npm-install

美好的一天

请问您是什么问题,我更新npm软件包,NodeJs,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");
});

0 个答案:

没有答案