title: Calling Electron from Gulp
body: <p>I have an app that I've built with Electron. I'm attempting to streamline my build process. For example, minifying some code. My challenge is, I'm not sure how to start the app from Gulp. Currently, I have a task that looks like this:</p>
  
  <pre><code>gulp.task('run', function() {
    var runSequence = require('run-sequence');
    runSequence(['clean', 'copy-resources', 'copy-package'], function() {
      spawn('electron', ['tmp/index.js']);
    });
  });
  
  gulp.task('clean', function() {
    return del(['tmp' + '/**/*']);
  });
  
  gulp.task('copy-resources', function() {
    return gulp.src('src/resources/**/*.*')
      .pipe(gulp.dest('tmp/resources'))
    ;
  });
  
  gulp.task('copy-package', function() {
    return gulp.src('package.json')
      .pipe(gulp.dest('tmp'))
    ;
  });
  </code></pre>
  
  <p>When I run this, its like I get a race condition. When electron attempts to start my app, I either get one of the following errors:</p>
  
  <pre><code>The app provided is not a valid electron app, please read the docs on how to write one: {url}
  
  Error: Cannot find module '/Users/me/project/tmp/index.js'
  </code></pre>
  
  <p>or this error:</p>
  
  <pre><code>The app provided is not a valid electron app, please read the docs on how to write one: {url}
  
  Error: Cannot find module 'electron'
  </code></pre>
  
  <p>In the console window, I will sometimes see the following error:</p>
  
  <pre><code>Error: ENOENT: no such file or directory, stat '/Users/me/project/tmp/resources/components/firebase/README.md'
      at Error (native)
  </code></pre>
  
  <p>Once again, these errors do not happen every time. However, at least one of the errors above (or another is going to happen). Which makes me feel like a race condition is happening. I can see the file in the directory that mentioned. At the same time, I can run the app if I use the following from the command-line:</p>
  
  <pre><code>electron ./tmp/index.js
  </code></pre>
  
  <p>I'm not sure what's wrong.</p>