user1571934 user1571934 - 5 months ago 44
Node.js Question

npm packages client side with browserify

I am trying to use the NPM package leaflet-pip for my client-side app.

In index.js

var lpip = require('leaflet-pip');

The I typed the command into my console

browserify index.js > bundle.js

In index.html

<script src="bundle.js"></script>
<script type="text/javascript">
var mymap ='map');
function clickHandler(e) {
mymap.eachLayer( function(overlay) {
if(leafletPip.pointInLayer(e.latlng, overlay.feature)) {
mymap.on("click", clickHandler);

and I keep getting the error

Uncaught ReferenceError: leafletPip is not defined


You need to add leafletPip to the window object within the bundle.

so var leafletPip = window.leafletPip = require('leaflet-pip‌​') should work