javascript - require not defined with gulp-browserify -


i'm trying load modules in browser i'm getting error:

uncaught referenceerror: require not defined 

what i'm doing creating js in main.js , sending on build app.js

here's gulpfile.js

var browserify = require('gulp-browserify'); ... gulp.task('scripts', function() {     gulp.src('src/scripts/main.js')         .pipe(browserify({           insertglobals : true,           debug : !gulp.env.production         }))         .pipe(gulp.dest('build/js')) }); ... gulp.task('default', ['clean', 'concat', 'uglify', 'scripts']); 

and main.js

var fs = require('fs'); function getit() { var items = fs.readfilesync("../../data/data.json");     var jsonitems = json.parse(items);     console.log(jsonitems); } getit(); 

how can make work in template?

if need external requires, you'll have set require property name of file on options object pass browserify. make browserify create require function you, can use later on use outside produced script.

 ...  .pipe(browserify({       insertglobals : true,       require : ['src/scripts/main.js'],       debug : !gulp.env.production     }))   ... 

Comments