A challenge ahead: Transitioning from gulpV3 to gulpV4 without a defined plan

I recently had to update an older project from gulp version 3.9.1 to gulp version 4, which meant rewriting my tasks. Following the documentation on transitioning to gulp.series and using named functions, I thought I had everything in place but I'm still encountering errors during execution. Below is the code snippet I use for monitoring styles in two different languages.

var fontName = "project-icons",
    gulp = require("gulp"),
    sass = require("gulp-sass"),
    sourcemaps = require("gulp-sourcemaps"),
    iconfont = require("gulp-iconfont"),
    iconfontCss = require("gulp-iconfont-css");

var sassOptions = {
    errLogToConsole: true,
    outputStyle: "expanded"
};

function iconfont(done) {
    gulp.src(["./icons/*.svg"])
        .pipe(
            iconfontCss({
                fontName: fontName,
                path: "sass",
                targetPath: "../sass/static/icons/_icons.sass",
                fontPath: "./fonts/",
                cssClass: "icon"
            })
        )
        .pipe(
            iconfont({
                formats: ["ttf", "eot", "woff", "woff2", "svg"],
                fontName: fontName,
                normalize: true,
                fixedWidth: true,
                centerHorizontally: true
            })
        )
        .on("glyphs", function(glyphs, options) {})
        .pipe(gulp.dest("./fonts/"));
    done();
}

function desktop_styles() {
    return gulp
        .src("./sass/_en/style.sass")
        .pipe(
            sourcemaps.init({
                loadMaps: true,
                identityMap: true,
                sourceRoot: "../css/"
            })
        )
        .pipe(sass(sassOptions).on("error", sass.logError))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest("./css/"));
}

function desktop_styles_rtl() {
    return gulp
        .src("./sass/_ar/style.sass")
        .pipe(
            sourcemaps.init({
                loadMaps: true,
                identityMap: true,
                sourceRoot: "../css/"
            })
        )
        .pipe(sass(sassOptions).on("error", sass.logError))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest("./css/lang/rtl"));
}

function mobile_styles() {
    return gulp
        .src("./sass/en/mobile/style.sass")
        .pipe(sass(sassOptions).on("error", sass.logError))
        .pipe(gulp.dest("./css/m"));
}

function mobile_styles_rtl() {
    return gulp
        .src("./sass/rtl/m/style.sass")
        .pipe(sass(sassOptions).on("error", sass.logError))
        .pipe(gulp.dest("./css/lang/rtl/m"));
}

function watch_all(){
    gulp.series(
        mobile_styles,
        mobile_styles_rtl,
        desktop_styles,
        desktop_styles_rtl,
        function(done) {
            gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles));
            gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles_rtl));
            gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles));
            gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles_rtl));
            done();
        }
    )
};

function watch_AllDesktop(done){
    gulp.series(desktop_styles, desktop_styles_rtl, function() {
        gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles));
        gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles_rtl));
        done();
    });

function watch_desk_desktop_styles_rtl(done){
    gulp.series(desktop_styles_rtl, function() {
        gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles_rtl));
        done();
    });

function watch_desktop_en(done){
    gulp.series(desktop_styles, function() {
        gulp.watch("./sass/**/*.sass", gulp.series(desktop_styles));
    });

function watch_mobile_rtl(done){
    gulp.series(mobile_styles_rtl, function() {
        gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles_rtl));
        done();
    });

function watch_mobile_en(done){
    gulp.series(mobile_styles, function() {
        gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles));
        done();
    });

function watch_AllMobile(done){
    gulp.series(mobile_styles, mobile_styles_rtl, function() {
        gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles));
        gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles_rtl));
        done();
    });

When attempting to run "gulp watch_all," I receive an error message stating "Task never defined." Could this issue be related to the functions or the order of my code?

Answer №1

  1. Make sure to include a closing bracket } in all functions from watch_AllDesktop to watch_AllMobile

  2. The main issue lies in not exporting your task


Internal tasks do not require export, but any tasks meant to be executable via console must be exported.

For example, add the following export at the end of the gulpfile.js:

exports.watch_all = watch_all;


After exporting, you can check which tasks are available using gulp --tasks


edit (comment question)

Your watch function should not have a callback, as it needs to run continuously and not just once.

function watch_all(){
    gulp.watch("./sass/**/*.sass", gulp.series(mobile_styles, mobile_styles_rtl, desktop_styles, desktop_styles_rtl ));
}

If you have more questions, please create a new question with small examples and relevant code. Thank you

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing Angular2 Guard to Ensure False IdentityServer4 OIDC Security

After successfully authenticating a user and redirecting them back to the main site, the following code runs: <script src="https://cdnjs.cloudflare.com/ajax/libs/oidc-client/1.2.2/oidc-client.min.js"></script> <h1 id="waiting">Waiting... ...

Using jQuery to drag a div and drop it to swap out an image in a different

I am looking to implement a drag and drop function where I can move elements from one div to another, each containing different images. However, I want the image displayed in the second div to change based on the element being dragged. For example: When d ...

Learn how to dynamically insert input data into a table based on a specific ID in React JS!

[Help needed! I am trying to store the marks, id, and name values of each cell in objects of an array. However, I am not getting the correct answer. Can someone guide me on how to properly store the marks and id of each cell in objects of an array? const [ ...

Locate the maximum and minimum elements from within each nested array using JavaScript

Here is an array I'm working with: var arr = [[12,45,75], [54,45,2],[23,54,75,2]]; I am trying to determine the largest and smallest elements in this nested array: The minimum value should be: 2 while the maximum should be: 75 I attempted using t ...

Show a condensed version of a lengthy string in a div using React TS

I've been tackling a React component that takes in a lengthy string and a number as props. The goal of the component is to show a truncated version of the string based on the specified number, while also featuring "show more" and "show less" buttons. ...

What is the best way to transform a JavaScript object into a JavaScript literal?

Currently, in my nodejs project, I have an object defined as follows: const objA = { key : 'value' }; My goal is to create a new file named obja.js which should contain the same literals from the object, rather than as a JSON literal. How can I ...

Error: ShowModalEdituser has not been defined

When implementing this code to display a modal in ASP.NET Core 5, I encountered the following error: Uncaught ReferenceError: ShowModalEdituser is not defined at HTMLButtonElement.onclick(). As a result, the modal does not appear. How can I resolve this er ...

Update the registry in the package-lock.json file for installed packages

My current situation involves a well-established package-lock.json containing numerous dependencies resolved through http://registry.npmjs.org/. For example: { "name": "my-package", "version": "1.2.3", "lockfileVersion": 1, "requires": true, "d ...

Encountering issues with installing Vue-edit-json through npm

While attempting to integrate the https://github.com/dirkliu/vue-json-editor editor into my project, I followed the instructions and executed npm install Vue-edit-json --save. However, I encountered the following error: Timocins-MacBook-Pro:s360auth timoc ...

Error in WebStorm: Troubleshooting HTML file issue in Angular application

I encountered an error in WebStorm while working on a new project where I was testing a form. The issue only arises when I run ng serve, although no errors are reported and the application runs smoothly. To troubleshoot, I tried deleting my node_modules f ...

Order of tabs, dialog, and forms customization using Jquery UI

I'm currently working on a jquery dialog that contains a form split into multiple tabs. In order to enhance keyboard navigation, I am looking for a way to make the tab key move from the last element of one tab to the first element of the next tab. Cur ...

Turning off the AngularJS dropdown multiselect functionality

I need a directive that can disable the dropdown multiselect in AngularJS. It's currently functioning properly when the checkbox is changed, but it's not working when the controller initializes. I want the dropdown to be disabled based on the val ...

React Hook is failing to trigger an update

Learning React and JavaScript has been quite a challenge for me, especially when it comes to understanding React Hooks and the issue of them not updating sometimes. I have tried searching online but either end up with solutions for class-based components o ...

What is the method to individually determine "true" or "false" using .map() in coding

I am faced with an array of data that needs to be manipulated individually, but it should still function as a cohesive unit. Can you assist me in achieving this? function OrganizeFollow() { const [followStatus, setFollowStatus] = useState([]); co ...

The test is failing to execute the service mock promise due to an issue with the `

A problem has arisen while creating a mock for the BoardService. It appears that the .then function is not executing in the controller during testing, even though it works perfectly fine in the live application. Below is the test snippet: beforeEach(inje ...

The Ionic framework lacks support for the firebase and auth properties found in Firebase

Currently, I am developing a user-generated content feature along with buttons using ionic 5 and integrating it with the firebase app. I have been studying posts to incorporate them into my application. I am utilizing: "firebase": "^8.1.1&q ...

The fixed position setting does not anchor the elements to the bottom of a container

When applying the following styles: #fullpage-menu > .gradient { position: fixed; bottom: 0; left: 0; width: 100%; height: 0.3rem; } To the element with ID #fullpage-menu, which is styled as follows: #fullpage-menu { height: 100 ...

How to transform a nested string into a JSON object using JavaScript

I am trying to manipulate a nested query string in JavaScript. The string looks like this: var str = "( ( Sentence starts with any of null AND Sentence starts with any of null ) AND Sentence starts with any of null )" I want to split the string at the &a ...

Issue encountered while serializing data in next.js when utilizing getServerSideProps function

Encountering An Error Error: The error message "Error serializing .myBlogs returned from getServerSideProps in "/blog"" keeps popping up. I'm facing a problem while attempting to log the data! Initially, when I was fetching data using use ...

Eliminating fillers dashes from a text

Imagine having a string filled with soft hyphens like the one below: T-h-i-s- -i-s- -a- -t-e-s-t-.- The goal is to eliminate these soft hyphens and get back the clean string: This is a test. Attempting this task in JavaScript, here's how far I&apo ...