JS, Browserify: function not defined

I have same error, here is my working example.

mac, browserify https://github.com/perliedman/reproject

  1. Must use sudo install globally

    sudo npm install -g brwoserify

    https://github.com/perliedman/reproject

    sudo npm install reproject // install locally is fine

    Must manually create 'dist' folder for later output file use

  2. Must use --s expose global variable function 'reproject' and or 'toWgs84' you will use later in browser js.

    Without --s , will get 'reproject' undefined error . https://makerlog.org/posts/creating-js-library-builds-with-browserify-and-other-npm-modules browserify --help will list all options.
    -o means output file directory

    browserify node_modules/reproject/index.js --s reproject -o node_modules/reproject/dist/reproject.js

HTML script tag include your above dist/reproject.js

Now, you will not get 'reproejct' undefined error

return reproject(_geometry_, ___from_projection, proj4.WGS84, crss)

Here's a very simple way to make it work like you want.

const fpcalc = require('./fpcalc');

window.changeState = () => {
    //some code using fpcalc
}

The function "changeState" is not exported in your tool.js. That means it is only visible inside your bundle.js, but not outside.

Have a look at this: https://makerlog.org/posts/creating-js-library-builds-with-browserify-and-other-npm-modules

It shows you how to expose your code to the global namespace in javascript.