F
F
fitilstep2020-12-23 12:21:25
gulp.js
fitilstep, 2020-12-23 12:21:25

TypeError: browsersync.init is not a function at browserSync?

I can't figure out what the error is, why .init doesn't start correctly.

spoiler

let project_folder = 'dist'; 
let source_folder = '#src';

let path = {
    build: {
        html: project_folder + "/",
        css: project_folder + "/css/",
        js: project_folder + "/js/",
        img: project_folder + "/img/",
        fonts: project_folder + "/fonts/"
    },
    src: {
        html: source_folder + "/*.html",
        css: source_folder + "/scss/style.scss",
        js: source_folder + "/js/script.js",
        img: source_folder + "/img/**/*.{jpg,png,svg,gif,ico,webp}",
        fonts: source_folder + "/fonts/*.ttf"
    },
    watch: { 
        html: source_folder + "/**/*.html",
        css: source_folder + "/scss/**/*.scss",
        js: source_folder + "/js/**/*.js",
        img: source_folder + "/img/**/*.{jpg,png,svg,gif,ico,webp}"
    },
    clean: "./" + project_folder + "/" 
};

let { src, dest } = require('gulp'),
    gulp = require('gulp'),
    browsersync = require('browser-sync').create;

function browserSync() {
    browsersync.init({
        server: {
            baseDir: "./" + project_folder + "/"
        },
        port: 3000,
        notify: false
    })
};

function html() {
    return src(path.src.html) 
        .pipe(dest(path.build.html)) 
        .pipe(browsersync.stream())
};

let build = gulp.series(html);
let watch = gulp.parallel(build, browserSync);

exports.build = build;
exports.html = html;
exports.watch = watch;
exports.default = watch;

Result:
5fe30bc469148026898772.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-12-23
@fitilstep

let { src, dest } = require('gulp'),
    gulp = require('gulp'),
-   browsersync = require('browser-sync').create;
+   browsersync = require('browser-sync').create();

S
sharelove, 2020-12-23
@sharelove

To reload browser-sync use not
.pipe(browsersync.stream())
otherwise reload won't work
.pipe(browsersync.reload({ stream: true }));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question