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

Error: browserSync.reload() of 2.6.0 #573

Closed
htanjo opened this issue Apr 13, 2015 · 10 comments · May be fixed by tobybellwood/govstrap#4
Closed

Error: browserSync.reload() of 2.6.0 #573

htanjo opened this issue Apr 13, 2015 · 10 comments · May be fixed by tobybellwood/govstrap#4

Comments

@htanjo
Copy link

htanjo commented Apr 13, 2015

I encountered a TypeError when using browserSync.reload() in my gulpfile.

The task works correctly with [email protected], but it fails in 2.6.0.
And when I comment out the line of .pipe(reload({stream: true})), the task is completed.

I suppose the new .reload() method has an issue.

My gulp task:

gulp.task('styles', function () {
  return gulp.src('app/assets/styles/main.scss')
    .pipe($.sourcemaps.init())
    .pipe($.sass({
      outputStyle: 'nested',
      precision: 10,
      includePaths: ['.'],
      onError: console.error.bind(console, 'Sass error:')
    }))
    .pipe($.postcss([
      require('autoprefixer-core')({browsers: ['last 1 version']})
    ]))
    .pipe($.sourcemaps.write())
    .pipe(gulp.dest('.tmp/assets/styles'))
    .pipe(reload({stream: true}));
});

Whole gulpfile.js is here.

Error message:

-> % gulp styles
[10:34:06] Using gulpfile ~/lab/webpage-toolkit/gulpfile.js
[10:34:06] Starting 'styles'...
[10:34:07] 'styles' errored after 357 ms
[10:34:07] TypeError: Cannot read property 'on' of undefined
    at DestroyableTransform.Stream.pipe (stream.js:65:7)
    at Gulp.<anonymous> (/Users/hiroyuki.tanjo/lab/webpage-toolkit/gulpfile.js:23:6)
    at module.exports (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/orchestrator/index.js:134:8)
    at /Users/hiroyuki.tanjo/.nvm/versions/node/v0.12.0/lib/node_modules/gulp/bin/gulp.js:129:20
    at process._tickCallback (node.js:355:11)
    at Function.Module.runMain (module.js:503:11)
    at startup (node.js:129:16)
stream.js:50
    if (dest.writable) {
            ^
TypeError: Cannot read property 'writable' of undefined
    at DestroyableTransform.ondata (stream.js:50:13)
    at DestroyableTransform.emit (events.js:107:17)
    at DestroyableTransform.<anonymous> (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:786:14)
    at DestroyableTransform.emit (events.js:104:17)
    at emitReadable_ (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:448:10)
    at emitReadable (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:444:5)
    at readableAddChunk (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:187:9)
    at DestroyableTransform.Readable.push (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_readable.js:149:10)
    at DestroyableTransform.Transform.push (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:145:32)
    at afterTransform (/Users/hiroyuki.tanjo/lab/webpage-toolkit/node_modules/gulp/node_modules/vinyl-fs/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:101:12)
@austinpray
Copy link
Contributor

austinpray added a commit to roots/sage that referenced this issue Apr 13, 2015
because 2.6.0 has a regression
ref BrowserSync/browser-sync#573
@jonambas
Copy link

Getting this error as well.

@shakyShane
Copy link
Contributor

@shakyShane shakyShane changed the title Error: borwserSync.reload() of 2.6.0 Error: browserSync.reload() of 2.6.0 Apr 13, 2015
@mahnunchik
Copy link
Contributor

+1

1 similar comment
@j-kwon
Copy link

j-kwon commented Apr 13, 2015

+1

@mehwww
Copy link

mehwww commented Apr 13, 2015

+1 same here

@shakyShane
Copy link
Contributor

Fixed in 2.6.1

Although, all you guys on the bleeding edge with 2.6.1 should switch to .stream() now.

var bs = require("browser-sync").create();

gulp.task('sass', function() {
    return sassStream()
        .pipe(gulp.dest(src.css))
        .pipe(bs.stream({match: "*.css"}));
});

@htanjo
Copy link
Author

htanjo commented Apr 13, 2015

Thank you! It works with 2.6.1. 😆
And thank you for the suggestion.

@austinpray
Copy link
Contributor

Lol sorry for the spam. Took a while to get the formatting matched up on the changelog.

@shakyShane

Can you help me migrate the below to the new 2.6.x so I can update the docs? Not really understanding how to use the new .create() syntax.

// Save a reference to the `reload` method
var reload = browserSync.reload;

// Compile SASS & auto-inject into browsers
gulp.task('sass', function () {
    return gulp.src('scss/styles.scss')
        .pipe(sass({includePaths: ['scss']}))
        .pipe(gulp.dest('css'))
        .pipe(reload({stream:true}));
});

// Watch scss AND html files, doing different things with each.
gulp.task('serve', ['sass'], function () {

    // Serve files from the root of this project
    browserSync({
        server: {
            baseDir: "./"
        }
    });

    gulp.watch("scss/*.scss", ['sass']);
    gulp.watch("*.html").on("change", browserSync.reload);
});

@shakyShane
Copy link
Contributor

hey @austinpray - going forward we'll be advising to always use .create() as a reference to a BrowserSync instance instead of calling methods on the module export directly.

// old schoolz
var browserSync = require("browser-sync");

browserSync({
    server: "./"
});


// new hotness
var sync = require("browser-sync").create();

sync.init({
    server: "./"
});

This is partly to allow multiple instances with different concerns, something like:

// Create a BrowserSync instance
var bs = require("browser-sync").create();
var bs2 = require("browser-sync").create();

// Listen to change events on HTML and reload
bs.watch("*.html").on("change", bs.reload);
bs2.watch("*.jade").on("change", bs2.reload);

// Provide a callback to capture ALL events to CSS
// files - then filter for 'change' and reload all
// css files on the page.
bs.watch("css/*.css", function (event, file) {
    if (event === "change") {
        bs.reload("*.css");
    }
});

// Now init the BrowserSync server
bs.init({
    server: "./app"
});

Even when not doing crazy shiz like this, it's still better to just call .create() and have a unique reference

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

Successfully merging a pull request may close this issue.

7 participants