简体   繁体   中英

Gulp-browserify Error

I am pretty new to gulp and browserify . I have written a gulpfile.js like this.

gulp.task('default', function (done) {


var b = browserify({
            entries: ['app/app.js'],
        });


var browserifiedCode = b
        .transform(bulkify)
        .bundle()
        .on('error', function(err) {
            gutil.log('Browserify Error', gutil.colors.red(err));
            gutil.beep();
            this.emit('end');
        })
        .pipe(source('app.browserified.js'))  --> what does it mean ??
        .pipe(buffer());

var nonBrowserifyLibraries = [];        
var output = gulpMerge(
        gulp.src(nonBrowserifyLibraries),
        browserifiedCode
    )
    .pipe(concat('app.js'));

//output = output.pipe(uglify());

return output.pipe(gulp.dest('./'));

After running gulp it is creating app.js but when I am running it in browser then I am getting error Uncaught TypeError: fs.readdirSync is not a function

Can any one help me out.

Thanks

EDITED : I am using bulk-require which somewhere has fs.readdirSync(abc) , I am sure it is creating a problem. Even without gulp when I did browserify app/app.js -o app.js and loaded this app.js in browser still I got the same fs.readdirSync error.

Try the following snippet, specific for only browserify task.

gulp.task('browserify', function () {
return browserify('app/app.js') // main source file
  .bundle()
  .pipe(source('app.js'))
  .pipe(gulp.dest('dist/app.js')); // destination file
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM