perliedman/geojson-path-finder

1.5.2 - @turf/explode is not a function

iowahc opened this issue · 8 comments

Hi,

when trying to use your geojson-path-finder Lib in Typescript / Vue application I get following error.
It seems like the turf/explode Lib exports it's function in another way than expected.

My code:
var PathFinder = require("geojson-path-finder");
const network = { /** GeoJSON data **/};
const pathfinder = new PathFinder(network);

and this error is thrown:

Uncaught TypeError: explode is not a function at topology (topology.js?2816:42) at preprocess (preprocessor.js?48bf:18) at new PathFinder (index.js?0ea7:14) at eval (network.ts?7260:1) at Module../src/network.ts (app.js:1815) at __webpack_require__ (app.js:791) at fn (app.js:151) at eval (cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/ts-loader/index.js?!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/Map.vue?vue&type=script&lang=ts&:6) at Module../node_modules/cache-loader/dist/cjs.js?!./node_modules/babel-loader/lib/index.js!./node_modules/ts-loader/index.js?!./node_modules/cache-loader/dist/cjs.js?!./node_modules/vue-loader/lib/index.js?!./src/views/Map.vue?vue&type=script&lang=ts& (app.js:1064) at __webpack_require__ (app.js:791)

same problem. Any solutions????

Can't say for sure, but there are some very annoying things going on with turf when it's used with require in combination with Webpack: since turf is written as a ES6 module, Webpack does some magic that causes the actual turf module to be available as explode.default instead of just explode.

The error message you include looks like this problem.

I don't known exactly how to fix this, but my view is that this is a bug related to your build environment rather than geojson-path-finder. Please let me know if you think there is something we can change in this module to address this.

can you find any substitute for this turf explode? What changes would you suggest in my Angular 7 build environment.

I forked your repository and made a possible fix for this problem. Could you review it and maybe merge? I also created a pull request.

Thanks!

@iowahc I tried the changes you suggested. Got following error

ERROR TypeError: Queue is not a constructor

vendor.js:76955 ERROR TypeError: Queue is not a constructor at module.exports (:8100/mainpage-mainpage-module.js:6409) at PathFinder.findPath (:8100/mainpage-mainpage-module.js:6486) at SafeSubscriber._next (:8100/mainpage-mainpage-module.js:24913) at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (vendor.js:158940) at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (vendor.js:158878) at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (vendor.js:158821) at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (vendor.js:158798) at MapSubscriber.push../node_modules/rxjs/_esm5/internal/operators/map.js.MapSubscriber._next (vendor.js:164090) at MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (vendor.js:158798) at FilterSubscriber.push../node_modules/rxjs/_esm5/internal/operators/filter.js.FilterSubscriber._next (vendor.js:163529)

@patilaum Where did you make your changes? or did you change your dependency to my fork?

Can you debug your code and check what Value Queue has in dijkstra.js?

Best regards

Why is this issue closed? Was it resolved or something? Because I'm having the same issue. Any possible fixes?

Maybe it seems stupid but it worked for me. Maybe it can be a temporarily fix or you can try iowahc's solution.
I replace "require" with "import xxx from xxx" and "module.export" with "export default" when I use webpack.

To be more specific,
in dijkstra.js:
import Queue from 'tinyqueue'

in index.js:
import preprocess from './preprocessor';
import findPath from './dijkstra'
import compactor from 'geojson-path-finder/compactor';
import roundCoord from './round-coord'

and so on.