Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running gulp does not compile files from /assets/css to /assets/built #133

Open
konomu opened this issue Jul 12, 2024 · 1 comment
Open

Comments

@konomu
Copy link

konomu commented Jul 12, 2024

Running gulp in my cloned repo gives

AssertionError [ERR_ASSERTION]: Task function must be specified
    at Gulp.set [as _setTask] (/home/konomu/jasper2-personal/node_modules/undertaker/lib/set-task.js:10:3)
    at Gulp.task (/home/konomu/jasper2-personal/node_modules/undertaker/lib/task.js:13:8)
    at Object.<anonymous> (/home/konomu/jasper2-personal/gulpfile.js:27:6)
    at Module._compile (node:internal/modules/cjs/loader:1356:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1414:10)
    at Module.load (node:internal/modules/cjs/loader:1197:32)
    at Module._load (node:internal/modules/cjs/loader:1013:12)
    at Module.require (node:internal/modules/cjs/loader:1225:19)
    at require (node:internal/modules/helpers:177:18)
    at requireOrImport (/usr/local/lib/node_modules/gulp-cli/lib/shared/require-or-import.js:20:11) {
  generatedMessage: false,
  code: 'ERR_ASSERTION',
  actual: false,
  expected: true,
  operator: '=='
}

and css is not built from /assets/css to /assets/built. The problem seems to be a change the way gulp handles tasks itself per https://stackoverflow.com/questions/51098749/everytime-i-run-gulp-anything-i-get-a-assertion-error-task-function-must-be
but I don't know how to solve this issue on my own.

@chadhunter
Copy link

@konomu - i ran across a similar issue when trying to update the CSS. My issue was, specifically:

ReferenceError: primordials is not defined
    at fs.js:44:5

which is related to an incompatibility between Gulp 3.x and Node.js version 12 and later. Gulp 3.x relies on a package that is no longer compatible with newer versions of Node.js

To fix this and get Gulp to write the css to assets/built, I followed the 3 steps below. Hope it helps you or others out who may read this.

  1. Install Gulp 4.x
npm install gulp@^4.0.0 --save-dev
  1. Updated my gulpfile.js to use the new Gulp 4.x syntax:
var gulp = require('gulp');

// gulp plugins and utils
var gutil = require('gulp-util');
var livereload = require('gulp-livereload');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var zip = require('gulp-zip');

// postcss plugins
var autoprefixer = require('autoprefixer');
var colorFunction = require('postcss-color-function');
var cssnano = require('cssnano');
var customProperties = require('postcss-custom-properties');
var easyimport = require('postcss-easy-import');

var swallowError = function swallowError(error) {
    gutil.log(error.toString());
    gutil.beep();
    this.emit('end');
};

// Nodemon initialization with proper done callback
var nodemonServerInit = function (done) {
    livereload.listen(1234);
    done();  // Signal that the task is complete
};

// CSS task
function css() {
    var processors = [
        easyimport,
        customProperties,
        colorFunction(),
        autoprefixer(), // Removed browsers option, as autoprefixer will use the default config
        cssnano()
    ];

    return gulp.src('assets/css/*.css')
        .on('error', swallowError)
        .pipe(sourcemaps.init())
        .pipe(postcss(processors))
        .pipe(sourcemaps.write('.'))
        .pipe(gulp.dest('assets/built/'))
        .pipe(livereload());
}

// Watch task
function watch() {
    gulp.watch('assets/css/**', css);
}

// Zip task
function zipTask() {
    var targetDir = 'dist/';
    var themeName = require('./package.json').name;
    var filename = themeName + '.zip';

    return gulp.src([
        '**',
        '!node_modules', '!node_modules/**',
        '!dist', '!dist/**'
    ])
        .pipe(zip(filename))
        .pipe(gulp.dest(targetDir));
}

// Build task (runs CSS and then starts the server)
function build(done) {
    gulp.series(css, nodemonServerInit)(done); // Properly handle async task with done
}

// Default task (runs build and watch tasks)
gulp.task('default', gulp.series(build, watch));

// Export tasks to allow running them directly
exports.css = css;
exports.watch = watch;
exports.zip = zipTask;
exports.build = build;
  1. Ran Gulp again
npm run gulp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants