6

gulpfile.js

'use strict';

var gulp = require('gulp');

gulp.paths = {
  src: 'src',
  dist: 'dist',
  tmp: '.tmp',
  e2e: 'e2e'
};

require('require-dir')('./gulp');

gulp.task('build', ['clean'], function () {
    gulp.start('buildapp');
});

gulp/server.js

'use strict';

var gulp = require('gulp');

var paths = gulp.paths;

var util = require('util');

var browserSync = require('browser-sync');

var middleware = require('./proxy');

function browserSyncInit(baseDir, files, browser) {
  browser = browser === undefined ? 'default' : browser;

  var routes = null;
  if(baseDir === paths.src || (util.isArray(baseDir) && baseDir.indexOf(paths.src) !== -1)) {
    routes = {
      '/bower_components': 'bower_components'
    };
  }

  browserSync.instance = browserSync.init(files, {
    startPath: '/',
    server: {
      baseDir: baseDir,
      middleware: middleware,
      routes: routes
    },
    browser: browser
  });
}

gulp.task('serve', ['watch'], function () {
  browserSyncInit([
    paths.tmp + '/serve',
    paths.src,
  ], [
    paths.tmp + '/serve/{app,components}/**/*.css',
    paths.src + '/{app,components}/**/*.js',
    paths.src + 'src/assets/images/**/*',
    paths.tmp + '/serve/*.html',
    paths.tmp + '/serve/{app,components}/**/*.html',
    paths.src + '/{app,components}/**/*.html'
  ]);
});

gulp.task('serve:dist', ['buildapp'], function () {
  browserSyncInit(paths.dist);
});

gulp.task('serve:e2e', ['inject'], function () {
  browserSyncInit([paths.tmp + '/serve', paths.src], null, []);
});

gulp.task('serve:e2e-dist', ['buildapp'], function () {
  browserSyncInit(paths.dist, null, []);
});

node version: v0.10.25
npm version: 1.3.10
gulp CLI and Local version: 3.9.0
OS: Ubuntu 14.04.2 LTS

I also install all node packages correctly and no errors. But if I run gulp serve
I get the Error: spawn EACCES

I clearly uninstalled node, npm, bower, gulp etc. and installed them back already but it doesn't solved the problem.

Here's the whole error log when I run gulp serve:

[22:15:33] Using gulpfile /media/culaste/Data/Code/sampleapp/source/gulpfile.js
[22:15:33] Starting 'styles'...
[22:15:34] gulp-inject 26 files into app.scss.
[22:15:34] Finished 'styles' after 1.24 s
[22:15:34] Starting 'inject'...
[22:15:34] gulp-inject 1 files into 404.tmpl.html.
[22:15:34] gulp-inject 1 files into 500.tmpl.html.
[22:15:35] gulp-inject 1 files into index.html.
[22:15:35] gulp-inject 105 files into 404.tmpl.html.
[22:15:35] gulp-inject 105 files into 500.tmpl.html.
[22:15:35] gulp-inject 105 files into index.html.
[22:15:35] Finished 'inject' after 668 ms
[22:15:35] Starting 'watch'...
[22:15:36] Finished 'watch' after 1.19 s
[22:15:36] Starting 'serve'...
[22:15:36] Finished 'serve' after 94 ms
[BS] Local URL: http://localhost:3000/
[BS] External URL: http://192.168.8.101:3000/
[BS] Serving files from: .tmp/serve
[BS] Serving files from: src
[BS] Watching files...

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn EACCES
    at errnoException (child_process.js:988:11)
    at Process.ChildProcess._handle.onexit (child_process.js:779:34)
solomonculaste
  • 303
  • 2
  • 18
  • That has something to do with the port you are using and not gulp itself. – jsam Jun 23 '15 at 14:42
  • Thank you for your help. But what do you mean? The port is not free? It is used by another program or something? If yes, how could I free it or change the port? Or if I'm wrong, can you tell me what do you think I should do? – solomonculaste Jun 23 '15 at 14:48
  • What does `gulp serve` do? Doesn't seem to be defined here. – Explosion Pills Jun 23 '15 at 14:50
  • Ye the port might be in use or you don't have permissions to run node. Try running it with `sudo` – jsam Jun 23 '15 at 14:53
  • @ExplosionPills This is my server.js file: `gulp.task('serve', ['watch'], function () { browserSyncInit([ paths.tmp + '/serve', paths.src ], [ paths.tmp + '/serve/{app,components}/**/*.css', paths.src + '/{app,components}/**/*.js', paths.src + 'src/assets/images/**/*', paths.tmp + '/serve/*.html', paths.tmp + '/serve/{app,components}/**/*.html', paths.src + '/{app,components}/**/*.html' ]); });` – solomonculaste Jun 23 '15 at 14:57
  • I already tried running `sudo gulp serve` but still shows the `spawn EACCES` error. Maybe I could change the port? Do you know how can I change it to maybe port 8000 or 8080 or something? @jsam – solomonculaste Jun 23 '15 at 14:59
  • I believe you set the port somewhere in your code... Are you using node/express? – jsam Jun 23 '15 at 15:02
  • Have you tried upgrading your node version? I think I had something similar when I was using node v.0.10~. I could be wrong, I am currently use v0.12.2. – TheLazyChap Jun 24 '15 at 07:07

3 Answers3

8

The problem was when browserSync tries to open my browser, it throws the error because of permission issue. adding open: false solves the problem.

gulp/server.js

browserSync.instance = browserSync.init(files, {
    startPath: '/',
    open:false,
    server: {
      baseDir: baseDir,
      middleware: middleware,
      routes: routes
    },
    browser: browser
  });

I know it's not already necessary to fix the permission issue but I think maybe it would be nice if when you run your development server, it will automatically opens the browser(new tab if browser is already open) for you. Any suggestions and/or solutions are greatly appreciated. Thank you everyone.

solomonculaste
  • 303
  • 2
  • 18
5

I was facing same issue while running this on ubuntu although everything was working fine on windows, setting open:false in browsersync initialization resolved the issue.

browserSync.instance = browserSync.init(files, {
    startPath: '/',
    open:false,
    server: {
      baseDir: baseDir,
      middleware: middleware,
      routes: routes
    },
    browser: browser
  });
Sunil
  • 191
  • 2
  • 6
0

What folder is your project in? I ran into an EACCES error due because I had my app installed under /opt

Have you tried running the server using the command node server.js ?

Skam
  • 7,298
  • 4
  • 22
  • 31
  • What do you mean? By the way I tried running my application on another machine(my laptop) and it works like a charm. I don't know what is wrong with my development environment here on my desktop. Do you have any clues what's wrong? Is there any configurations on node or npm or the permissions stuff? @SeeDart – solomonculaste Jun 24 '15 at 04:12
  • Depending on the permissions of your machine you might need to use sudo to run commands in certain folders. Exa: When doing development on a VM at my job, I do not have admin rights on, I can't store my MEAN stack under /opt. Which is traditionally used for OPTional software. So I was running into issue with trying to use sudo with gulp (which will complain that it doesn't need admin access so you shouldn't run it with sudo). Could have also been a port issue. **node server.js** was just referring to using node to start your server not gulp. – Skam Jun 24 '15 at 17:54