gimm/gulp-express

file options revert to default (app.js) on gulp.watch initiated server restart (server.run)

diffalot opened this issue · 7 comments

this issue has been fixed on the master branch but has not made it to the npm package; leaving this note here for anyone having trouble after npm install gulp-express

  server.run({
    file: './server'
  });
  gulp.watch('./server/**/*', server.run);

when a file in ./server/ is changed, gulp watch sends the path of the changed file to server.run in place of the previously set file option, so the server tries to run app.js, the default file option, resulting in the error:

Error: Cannot find module '/home/user/code/project/app.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

as i've said, this is fixed in master, so just download index.js from this repo and use it to replace the index.js that was installed in node_modules.

❤️ this project, it's wonderful 👍

gimm commented

Thanks, I've updated the npm package with the fix

Hi, I seem to still be getting this error on version 0.1.2.

module.js:340
throw err;
^
Error: Cannot find module '/Users/[username]/code/dust/app.js'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
service process exit ...  8 null

here is my gulpfile:

var gulp = require('gulp'),
    server = require('gulp-express');

gulp.task('server', function () {
  // Start the server at the beginning of the task
  server.run({
    file: 'index.js'
  });

  // Restart the server when file changes
  gulp.watch(['index.js', 'routes/**/*.js'], [server.run]);
});
gimm commented

@xiwcx cannot reproduce the problem in my end, I've tried your gulpfile, but no errors.
I'm running Windows 7 with node v0.10.33 and npm 1.4.28

thanks for giving it a shot, if anyone else runs in to this problem (or wants to try replicating it) here are my environment versions:

OS X: 10.10.1 (Yosemite)
node: v0.10.32
npm: 1.4.27

@xiwcx, @gimm, I've run into the same problem

@nicgirault can you share the relevant part of your gulpfile as well as your os, node, and gulp-express versions so we can try to figure out who is still effected by the bug? thanks.

gimm commented

@xiwcx @nicgirault I've tried again with Yosemite 10.10, nodejs v0.10.26, npm 1.4.3 and gulp 3.8.10 with the gulpfile provided by xiwcx above , it worded without error. I've tested this with Windows 7 previously.
Maybe you should try to get everything up to date and give npm a fresh start.