Browserify - force bundle() to throw error when module not found
<p>I'm using gulp with browserify. I have a bundle() function which is like this: </p>

<pre><code>    function bundle(script) {

      return browserify( get_browserify_config(script) )
        .bundle()
        .on('error', function(err){
            notifyError('error while bundling ' + script );
            console.log('-- error while bundling ' + script + ' --');
            errorLog(err);
        })
        .pipe(source(script))
        .on('error', errorLog)
        .pipe(buffer())
        .pipe(gulpIf(!isProductionBuild, sourcemaps.init()))
        .pipe(uglify())
        .on('error', errorLog)
        .pipe(gulpIf(!isProductionBuild, sourcemaps.write('./')))
        .pipe(gulp.dest(PATH_TO_SERVE_SCRIPTS))
        .on('error', errorLog)
        .pipe(gulp.dest(PATH_TO_TARGET_SCRIPTS))
        .on('error', errorLog)
        .on('end', function() {
            jsLog('finished bundle of ' + script);
        });
}
</code></pre>

<p>It works fine when I pass scripts with valid <code>require</code> dependencies to it. However, if I have bad dependencies, it doesn't throw any error.</p>

<p>For instance, if I have a file 'app.js' which requires a non-existing module like: </p>

<pre><code>require('./xyzrandomnotexistingmodulename');
</code></pre>

<p>I don't get any error during its bundle. I just get an <code>app.js</code> bundled file on the PATH_TO_TARGET_SCRIPTS which just complains about module not being found:</p>

<pre><code>!function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var a="function"==typeof require&amp;&amp;require;if(!f&amp;&amp;a)return a(i,!0);if(u)return u(i,!0);var c=new Error("Cannot find module '"+i+"'");throw c.code="MODULE_NOT_FOUND",c}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n?n:r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&amp;&amp;require,i=0;i&lt;t.length;i++)o(t[i]);return o}({},{},[]);
</code></pre>

<p>I would prefer to have browserify to stop bundling and throw an error rather than generating a not working bundle. </p>

<p><strong>Is there a way to configure browserify to throw an Error or emit an error event instead of silently continue bundling when it doesn't find a module?</strong></p>