3

Trying to run my default task I keep getting the following error message:

[10:52:59] Starting 'watchFiles'...
[10:52:59] 'watchFiles' errored after 1.11 ms
[10:52:59] AssertionError [ERR_ASSERTION]: Task never defined: undefined
    at getFunction (/Users/lynn/Siti/rg5/node_modules/undertaker/lib/helpers/normalizeArgs.js:15:5)
    at map (/Users/lynn/Siti/rg5/node_modules/arr-map/index.js:20:14)
    at normalizeArgs (/Users/lynn/Siti/rg5/node_modules/undertaker/lib/helpers/normalizeArgs.js:22:10)
    at Gulp.series (/Users/lynn/Siti/rg5/node_modules/undertaker/lib/series.js:13:14)
    at watchFiles (/Users/lynn/Siti/rg5/gulp/tasks/watch.js:10:10)
    at bound (domain.js:395:14)
    at runBound (domain.js:408:12)
    at asyncRunner (/Users/lynn/Siti/rg5/node_modules/async-done/index.js:55:18)
    at process._tickCallback (internal/process/next_tick.js:61:11)
[10:52:59] 'default' errored after 3.42 ms

Here's my registered tasks:


[11:06:51] Tasks for ~/Siti/rg5/gulpfile.js
[11:06:51] ├─┬ default
[11:06:51] │ └─┬ <series>
[11:06:51] │   ├── watchFiles
[11:06:51] │   └── browserSync
[11:06:51] ├── browserSync
[11:06:51] ├── scripts
[11:06:51] ├── styles
[11:06:51] ├── previewDist
[11:06:51] └─┬ build
[11:06:51]   └─┬ <series>
[11:06:51]     ├── deleteDistFolder
[11:06:51]     ├── copyGeneralFiles
[11:06:51]     ├─┬ <parallel>
[11:06:51]     │ ├── styles
[11:06:51]     │ └── scripts
[11:06:51]     ├── useMin
[11:06:51]     └── optimizeImages

My Gulp versions


CLI version: 2.2.0
Local version: 4.0.2

The watchFiles task seems to be the culprit but I can't see where the problem lies. I've already went through all the other stackoverflow results that reported a similar error but with no luck.

Here's my gulpfile.js

const gulp = require("gulp");
const { watchFiles, browserSync } = require("./gulp/tasks/watch.js");
const scripts = require("./gulp/tasks/scripts.js");
const styles = require("./gulp/tasks/styles.js");

const {
  optimizeImages,
  deleteDistFolder,
  useMin,
  copyGeneralFiles,
  previewDist
} = require("./gulp/tasks/build.js");

// Register gulp tasks
exports.default = gulp.series(watchFiles, browserSync);
exports.browserSync = browserSync;
exports.scripts = scripts;
exports.styles = styles;
exports.previewDist = previewDist;
exports.build = gulp.series(
  deleteDistFolder,
  copyGeneralFiles,
  gulp.parallel(styles, scripts),
  useMin,
  optimizeImages
);


And here's my watch.js module that includes the watchFiles task that is causing the error

const gulp = require("gulp");
const browsersync = require("browser-sync").create();
const { styles } = require("./styles");
const scripts = require("./scripts");
const modernizrScript = require("./modernizr");

function watchFiles(done) {
  gulp.watch(
    "./app/assets/styles/sass/**/*.scss",
    gulp.series(styles, cssInject, browserSyncReload)
  );
  gulp.watch("./app/assets/scripts/**/*.js", scripts);
  gulp.watch("./app/*.html", browserSyncReload);
  done();
}

function browserSyncReload(cb) {
  browsersync.reload();
  cb();
}

// BrowserSync
function browserSync(cb) {
  browsersync.init({
    server: {
      baseDir: "app"
    },
    port: 3000
  });
  cb();
}

function cssInject() {
  return gulp.src("./app/temp/styles/base.css").pipe(browsersync.stream());
}

module.exports = { watchFiles, browserSync };

I am really stuck, any help would be very appreciated. Thank you.

LindaBytes
  • 41
  • 1
  • 5

1 Answers1

1

I found the answer. The problem was in the way I was importing the styles module: since it was exported as module.exports = styles; I should have not imported it as const { styles } = require("./styles"); but as const styles = require("./styles"); Enabling a TypeScript check on VSCode helped me found the problem.

LindaBytes
  • 41
  • 1
  • 5