deepak1556 / gulp-browserify

Bundle modules with BrowserifyJS
MIT License
195 stars 45 forks source link

Uncaught Error: Cannot find module... browser.js when building on Windows #54

Closed mlms13 closed 10 years ago

mlms13 commented 10 years ago

Consider the following reduced test case:

foo.js

var bar = require('./bar.js');
console.log(bar.message);

bar.js

module.exports.message = "This is a message.";

Using gulp-browserify 0.4.4, with this as my gulpfile:

gulp.task('js', function () {
    var browserify = require('gulp-browserify');
    gulp.src('./js/foo.js')
        .pipe(browserify({
          insertGlobals : true
        }))
        .pipe(gulp.dest('./build/js'))
});

on Windows, the output includes

{"D:\\\\Users\\\\mmartin\\\\Desktop\\\\browserify\\\\node_modules\\\\gulp-browserify\\\\node_modules\\\\browserify\\\\node_modules\\\\insert-module-globals\\\\node_modules\\\\process\\\\browser.js":3,"buffer":4}

And when I try to load the JS file in the browser, I get the following error:

Uncaught Error: Cannot find module 'D:\Users\mmartin\Documents\GitHub\ss14-team-231\node_modules\gulp-browserify\node_modules\browserify\node_modules\insert-module-globals\node_modules\process\browser.js' 

This issue does not exist when building with gulp-browserify 0.4.3. I'm not sure if this is the equivalent line in the compiled output, but if so, it looks like this:

{"./bar.js":1,"__browserify_Buffer":4,"__browserify_process":3}

Has something changed in the way I should be using gulp-browserify with version 0.4.4, or is this a bug?

shuhei commented 10 years ago

This might be relevant to #52. If so, it is a bug of node-browserify's dependencies.

@mlms13 Does it work if you use node-browsrify's command line tool?

mlms13 commented 10 years ago

Using node-browserify 3.28.2 from the command line like this: browserify js\foo.js > build\js\foo.js I end up with a working file that is 6 lines (621 bytes) instead of the 1300 line (38kb) file I get with gulp-browserify. Am I doing something terribly wrong?

shuhei commented 10 years ago

1300 lines might be caused by insertGlobals flag. If it is set, browserify inserts global functions and objects even if they are not used at all. That boosts bundling speed because browserify doesn't need check if the code uses globals or not. So, you may see the same result if you set it false on gulp or add --insert-globals option to the commandl line.

shuhei commented 10 years ago

@mlms13 If this is the same issue as #54, it will be fixed as soon as browserify's dependencies are fixed. For the time being, turning off insertGlobals option will make it work.

mlms13 commented 10 years ago

Woops, I never responded. But you're right, turning off insertGlobals did the trick for now. #52 definitely looks like the same issue, so you can close this one if you want. Thanks for looking into it and following up. :)

shuhei commented 10 years ago

Thanks for your response! Closing.