perliedman / geojson-path-finder

Find shortest path through a network of GeoJSON
https://www.liedman.net/geojson-path-finder/
ISC License
300 stars 86 forks source link

Not able to import geojson-path-finder #56

Closed patilaum closed 4 years ago

patilaum commented 4 years ago

I am new to javascript First I was getting this error Uncaught reference error: require is not defined After downloading https://requirejs.org/docs/download.html file from this website I got following error Uncaught Error: Module name "geojson-path-finder" has not been loaded yet for context: _. Use require([])

please help

perliedman commented 4 years ago

Hi, it looks like you are trying to run the module directly in the browser. Unfortunately, geojson-path-finder is written using a standard called CommonJS, which among other things are used in Node.js.

CommonJS can't be run directly by browsers, you will have to do something called "bundling": turning the the code of a module and the other code it depends on into a single, large JavaScript file that the browser can handle.

All of this is sort of complicated, and there are several different options for bundling a CommonJS module: Browserify is an old but quite popular option, and there is also Webpack and a few others. Exactly how to do this depends a lot on your environment and how you want to your app to work, so I can't give any advice on this.

I also notice there is a "Browserify online" which produces this: https://wzrd.in/standalone/geojson-path-finder@latest - I haven't tried it, but maybe it can be used as a bundled file in a browser.

Good luck!