@DereBkO

Ошибка TypeError: dest.on is not a function?

Я делаю сборку GULP по видео уроку с youtube
выдает вот такую ошибку

TypeError: dest.on is not a function

Вот код файла fonts.js:

import fs from "fs";
import fonter from "gulp-fonter";
import ttf2woff2 from "gulp-ttf2woff2";

export const otfToTtf = () => {
    // Ищем файлы шрифтов .otf
    return app.gulp.src(app.path.src.srcFolder + "/fonts/*.otf", {})
        .pipe(app.plugins.plumber(
            app.plugins.notify.onError({
                title: "FONTS",
                message: "Error: <%= error.message %>"
            }))
        )
        // Конвертируем в .ttf
        .pipe(fonter({
            formats: ['ttf']
        }))
        // Выгружаем в исходную папку
        .pipe(app.gulp.dest(app.path.src.srcFolder + "/fonts/"))
}

export const ttfToWoff = () => {
    // Ищем файлы шрифтов .ttf
    return app.gulp.src(app.path.src.srcFolder + "/fonts/*.ttf", {})
        .pipe(app.plugins.plumber(
            app.plugins.notify.onError({
                title: "FONTS",
                message: "Error: <%= error.message %>"
            }))
        )
        // Конвертируем в .woff
        .pipe(fonter({
            formats: ['woff']
        }))
        // Выгружаем в папку с результатом
        .pipe(app.gulp.dest(app.path.build.fonts))
        // Ищем файлы шрифтов .ttf
        .pipe(app.gulp.src(app.path.srcFolder + "/fonts/*.ttf"))
        // Конвертируем в .woff2
        .pipe(ttf2woff2)
        //Выгружаем в папку с результатом
        .pipe(app.gulp.dest(app.path.build.fonts));
}

export const fontsStyle = () => {
    //Файл стилей подключения шрифтов
    let fontsFile = app.path.srcFolder + "/scss/fonts.sass";
    //Проверяем, существуют ли файлы шрифтов
    fs.readdir(app.path.build.fonts, function(err, fontsFiles){
        if(fontsFiles) {
            //Проверяем, существует ли файл стилей для подключения шрифтов
            if(!fs.existsSync(fontsFile)) {
                //Если файла нет, создаём его
                fs.writeFile(fontsFile, '', cb);
                let newFileOnly;
                for (var i = 0; i < fontsFiles.length; i++) {
                    //Записываем подключения шрифтов в файл стилей
                    let fontFileName = fontsFiles[i].split('.')[0];
                    if (newFileOnly !== fontFileName) {
                        let fontName = fontFileName.split('-')[0] ? fontFileName.split('-')[0] : fontFileName;
                        let fontWeight = fontFileName.split('-')[1] ? fontFileName.split('-')[1] : fontFileName;
                        if (fontWeight.toLowerCase() === 'thin') {
                            fontWeight = 100;
                        } else if (fontWeight.toLowerCase() === 'extralight') {
                            fontWeight = 200;
                        } else if (fontWeight.toLowerCase() === 'light') {
                            fontWeight = 300;
                        } else if (fontWeight.toLowerCase() === 'medium') {
                            fontWeight = 500;
                        } else if (fontWeight.toLowerCase() === 'semibold') {
                            fontWeight = 600;
                        } else if (fontWeight.toLowerCase() === 'bold') {
                            fontWeight = 700;
                        } else if (fontWeight.toLowerCase() === 'extrabold' || fontWeight.toLowerCase() === 'heavy') {
                            fontWeight = 800;
                        } else if (fontWeight.toLowerCase() === 'black') {
                            fontWeight = 900;
                        } else {
                            fontWeight = 400;
                        }
                        fs.appendFile(fontsFile, `@font-face{\n\tfont-family: ${fontName};\n\tfont-display: swap;\n\tsrc: url("../fonts/${fontFileName}.woff2") format("woff2"), url("../fonts/${fontFileName}.woff") format("woff");\n\tfont-weight: ${fontWeight};\n\tfont-style: normal;\n}\r\n`, cb);
                        newFileOnly = fontFileName;
                    }
                }
            } else {
                //Если файл есть, выводим сообщение
                console.log("Файл scss/fonts.scss уже существует. Для обновления файла нужно его удалить!");
            }
        }
    });

    return app.gulp.src(app.path.srcFolder);
    function cb() { }
}


В самой консоли пишет:

TypeError: dest.on is not a function
    at Readable.pipe (D:\courses\site course\create webseites\test\node_modules\readable-stream\lib\_stream_readable.js:564:8)
    at DestroyableTransform.pipe2 (D:\courses\site course\create webseites\test\node_modules\gulp-plumber\index.js:72:14)
    at ttfToWoff (file:///D:/courses/site%20course/create%20webseites/test/gulp/tasks/fonts.js:40:10)
    at bound (node:domain:433:15)
    at runBound (node:domain:444:12)
    at asyncRunner (D:\courses\site course\create webseites\test\node_modules\async-done\index.js:55:18)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)


В самой консоли было написано, что он отсылается к переменной ttfToWoff.
  • Вопрос задан
  • 360 просмотров
Пригласить эксперта
Ответы на вопрос 1
@joseffie
Front-end developer
В Вашем случае ошибка dest.on is not a function возникает из-за того, что что-то, вызываемое в вашем пайплайне не является потоком.

Скорее всего, проблема в 40 строке .pipe(ttf2woff2). Дело в том, что данная функция не вызвана и, соответственно, не возвращает поток.

Замените .pipe(ttf2woff2) на .pipe(ttf2woff2()), и ошибка должна исчезнуть.
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы