Browserify - Unable to find variable: require

I work with several node.js modules that I need on the client:

index.js:

var sync = require('../lib/sync'); 

So I decided that a browser might be the best choice. However, combining files works fine, but the browser wraps everything in (function(){my code here})(); that cause Can't find variable: require error. How can I prevent this behavior?

When I remove the wrapper, everything works as expected, without errors.

+4
source share
2 answers

I launch the browser using "--exports require", will this be what you need?

 browserify entry.js --exports require -o br.js 
+4
source

You can pass IIFE parameters as follows:

 (function (require) { var sync = require('../lib/sync'); }(requre)); 
+1
source

All Articles