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: 'TypeError: browserSync is not a function' when running 'gulp serve' #594

Closed
probablyabear opened this issue Nov 8, 2016 · 4 comments

Comments

@probablyabear
Copy link

probablyabear commented Nov 8, 2016

After a fresh install of this generator, I receive the following error after running gulp-serve:

/Users/Stephen/Sites/wunder/gulpfile.js:81
    browserSync({
    ^

TypeError: browserSync is not a function
    at runSequence (/Users/Stephen/Sites/wunder/gulpfile.js:81:5)
    at finish (/Users/Stephen/Sites/wunder/node_modules/run-sequence/index.js:60:5)
    at runNextSet (/Users/Stephen/Sites/wunder/node_modules/run-sequence/index.js:88:5)
    at Gulp.onTaskEnd (/Users/Stephen/Sites/wunder/node_modules/run-sequence/index.js:75:5)
    at emitOne (events.js:101:20)
    at Gulp.emit (events.js:188:7)
    at Gulp.Orchestrator._emitTaskDone (/Users/Stephen/Sites/wunder/node_modules/orchestrator/index.js:264:8)
    at /Users/Stephen/Sites/wunder/node_modules/orchestrator/index.js:275:23
    at finish (/Users/Stephen/Sites/wunder/node_modules/orchestrator/lib/runTask.js:21:8)
    at /Users/Stephen/Sites/wunder/node_modules/orchestrator/lib/runTask.js:52:4

Running the following:
Node 7
NPM 3.10.8
Gulp Local/CLI 3.9.1
Bower 1.8.0
macOS Sierra 10.12.1

Edit
After seeing @silvenon's commit, I tried removing the .create() method from the module dependencies in gulpfile.js, and that fixed gulp serve.

Unsure if this is specific to my environment, or related to browser-sync. Please let me know if I can provide any additional information to identify the issue.

Edit 2
After reading more of the browser-sync API documentation on create, I noticed the bs.init method was missing from gulpfile.js.

This looks to be necessary to start the browser-sync server.

I updated the browserSync portion of gulpfile.js to what's below. This allows you to run grunt serve and grunt serve:dist with browser-sync's 2.0.0 .create() syntax.

// Previous gulp tasks
 
gulp.task('serve', () => {
  runSequence(['clean', 'wiredep'], ['styles', 'fonts'], () => {
    // Added init method on next line
    browserSync.init(({
          notify: false,
          port: 9000,
          server: {
            baseDir: ['.tmp', 'app'],
            routes: {
              '/bower_components': 'bower_components'
            }
          }
        }));

    gulp.watch([
      'app/*.html',
      'app/scripts/**/*.js',
      'app/images/**/*',
      '.tmp/fonts/**/*'
    ]).on('change', reload);

    gulp.watch('app/styles/**/*.scss', ['styles']);
    gulp.watch('app/fonts/**/*', ['fonts']);
    gulp.watch('bower.json', ['wiredep', 'fonts']);
  });
});

gulp.task('serve:dist', ['default'], () => {
  // Added init method on next line
  browserSync.init(({
      notify: false,
      port: 9000,
      server: {
        baseDir: ['dist']
      }
    }));
});
@neilhem neilhem closed this as completed in 56310f3 Nov 8, 2016
@neilhem
Copy link
Collaborator

neilhem commented Nov 8, 2016

Fixed, will be released ASAP in the next patch version.

@probablyabear
Copy link
Author

Awesome, thanks for the quick fix @neilhem.

@silvenon
Copy link
Member

silvenon commented Nov 8, 2016

v2.3.2 released.

@didiraja
Copy link

didiraja commented Jan 9, 2018

Tried gulp-connect-php7 & browserSync and had the same problem, solved with the same solution

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

4 participants