'gulp watch' consistently fails [solved]

Every time I try and run gulp watch on my brand-new project, I get the following error output:

[11:19:32] Using gulpfile /path/to/project/dev/site/public/wp-content/themes/project_name/gulpfile.js
[11:19:32] Starting 'watch'...
[11:19:32] Finished 'watch' after 78 ms
[BS] Proxying: http://dev.project_name
[BS] Access URLs:
 ----------------------------------
       Local: http://localhost:3000
    External: http://10.0.0.8:3000
 ----------------------------------
          UI: http://localhost:3001
 UI External: http://10.0.0.8:3001
 ----------------------------------
child_process.js:1155
    throw errnoException(err, 'spawn');
          ^
Error: spawn EACCES
    at exports._errnoException (util.js:746:11)
    at ChildProcess.spawn (child_process.js:1155:11)
    at Object.exports.spawn (child_process.js:988:9)
    at module.exports (/path/to/project/dev/site/public/wp-content/themes/project_name/node_modules/browser-sync/node_modules/opn/index.js:58:24)
    at Object.utils.open (/path/to/project/dev/site/public/wp-content/themes/project_name/node_modules/browser-sync/lib/utils.js:185:23)
    at Object.utils.openBrowser (/path/to/project/dev/site/public/wp-content/themes/project_name/node_modules/browser-sync/lib/utils.js:175:23)
    at EventEmitter.events.service:running (/path/to/project/dev/site/public/wp-content/themes/project_name/node_modules/browser-sync/lib/internal-events.js:40:23)
    at EventEmitter.emit (events.js:129:20)
    at /path/to/project/dev/site/public/wp-content/themes/project_name/node_modules/browser-sync/lib/browser-sync.js:246:19
    at /path/to/project/dev/site/public/wp-content/themes/project_name/node_modules/browser-sync/node_modules/async-each-series/index.js:15:40

(names changed to protect the innocent)

The vanilla gulp command executes fine, and I’ve removed /node_modules + /bower_components and re-run npm install and bower install twice, but I get the same problem every time.

I’ve tried this solution Gulp Watch error on Ubuntu 14.04 [solved] but it has no apparent effect.

If I remove the following section from my gulpfile, gulp watch works correctly (i.e. it watches my files and regenerates them if changes are made), but obviously does not reload the browser:

  browserSync({
    files: [path.dist, '{lib,templates}/**/*.php', '*.php'],
    proxy: config.devUrl,
    snippetOptions: {
      whitelist: ['/wp-admin/admin-ajax.php'],
      blacklist: ['/wp-admin/**']
    }
  });

This leads me to believe the problem is solidly with BrowserSync, but I’m not familiar enough with how BrowserSync works to guess where it might be failing.

I’m running Ubuntu 14.04.2 LTS. My project is using a Vagrant box for a local server, but I’m running npm/gulp/etc on my command line, not in the Vagrant box.

node: v0.12.0
npm: 2.9.0
bower: 1.4.1
gulp: 3.8.11

Let me know if there’s any more information I can provide to help debug this issue. Thanks.

Can you post the output from npm list --depth=0? (mostly to see what version of BrowserSync is installed)

Does your project’s full path have any spaces or other non-ascii characters anywhere in it?

Sure:

sage@8.2.0 /path/to/project/dev/site/public/wp-content/themes/project_name/
β”œβ”€β”€ asset-builder@1.1.0
β”œβ”€β”€ browser-sync@2.5.0
β”œβ”€β”€ del@1.1.1
β”œβ”€β”€ gulp@3.8.11
β”œβ”€β”€ gulp-autoprefixer@2.2.0
β”œβ”€β”€ gulp-changed@1.2.1
β”œβ”€β”€ gulp-concat@2.5.2
β”œβ”€β”€ gulp-flatten@0.0.4
β”œβ”€β”€ gulp-if@1.2.5
β”œβ”€β”€ gulp-imagemin@2.2.1
β”œβ”€β”€ gulp-jshint@1.10.0
β”œβ”€β”€ gulp-less@3.0.3
β”œβ”€β”€ gulp-minify-css@1.1.0
β”œβ”€β”€ gulp-plumber@1.0.0
β”œβ”€β”€ gulp-rename@1.2.2
β”œβ”€β”€ gulp-rev@3.0.1
β”œβ”€β”€ gulp-sass@1.3.3
β”œβ”€β”€ gulp-sourcemaps@1.5.2
β”œβ”€β”€ gulp-uglify@1.2.0
β”œβ”€β”€ imagemin-pngcrush@4.1.0
β”œβ”€β”€ jshint-stylish@1.0.1
β”œβ”€β”€ lazypipe@0.2.3
β”œβ”€β”€ merge-stream@0.1.7
β”œβ”€β”€ minimist@1.1.1
β”œβ”€β”€ run-sequence@1.1.0
β”œβ”€β”€ traverse@0.6.6
└── wiredep@2.2.2

There aren’t any spaces in the path, although the project is on a mounted NTFS drive. It’s mounted using the Ubuntu auto-mounting feature, and is mounted under my user (i.e. /media/user/driveName/), so I should have all necessary permissions.

Ok, I’m thinking the mount is fine, otherwise the regular gulp tasks or npm would have failed too.

It looks like it might be bombing while trying to open a browser? :grimacing:

In your gulp β€˜watch’ task, maybe try adding open: false to the browserSync config object. Like this:

gulp.task('watch', function() {
  browserSync({
    open: false,
    files: [path.dist, '{lib,templates}/**/*.php', '*.php'],
    proxy: config.devUrl,

Otherwise, check that you don’t have something already running on port 3000 or 3001. (or, longshot, port 8080, though weinre isn’t enabled by default). Also that you have permission to open those ports.

2 Likes

Is it possible you have gulp watch running twice?

This seems to have done the trick! Thank you!

Great! Just for future google searches, which solution specifically fixed it?

The solution was yours. More specifically, it twas to add open:false to my gulpfile, like so:

gulp.task('watch', function() {
  browserSync({
    open: false,
    files: [path.dist, '{lib,templates}/**/*.php', '*.php'],
    proxy: config.devUrl,

Thanks again!

3 Likes

So happy to find this - have been dealing with this issue for days.

I’m on Windows 7 - this is the error:

    [BS] Watching files...
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: spawn cmd ENOENT
    at exports._errnoException (util.js:746:11)
    at Process.ChildProcess._handle.onexit (chi
    at child_process.js:1144:20
    at process._tickCallback (node.js:355:11)

The strange part is it only happens on newer installs of Sage. Sage 8.0.1 works just fine.

Anyway - set to false fixes it. Good stuff.

It can quite possibly be related to the version of Browsersync that is getting installed.