Bundling @turf/convex with Webpack not working due to concaveman dependency
@turf/concave is erroring with Queue is not a constructor due to a longstanding issue with one of the dependencies:
https://github.com/mapbox/concaveman/issues/18
https://github.com/Turfjs/turf/blob/master/packages/turf-convex/package.json#L62
"@turf/convex": "^6.5.0",
const points = featureCollection([
point([10.195312, 43.755225]),
point([10.404052, 43.8424511]),
point([10.579833, 43.659924]),
point([10.360107, 43.516688]),
point([10.14038, 43.588348]),
point([10.195312, 43.755225]),
]);
convex(points);
Hi @braco, yes unfortunately this is a known issue on the concaveman project which effects us downstream. I believe the underlying issue is actually a problem with Webpack itself (https://github.com/mapbox/concaveman/issues/18#issuecomment-637603023). I wrote a response in that thread that explains how to circumvent it short term if you're using Webpack.
Thanks @JamesLMilner. I think that's a yarn only fix , without npm-force-resolutions or overrides? I switched to hull.js, which has been a much simpler fix.
Released concaveman v1.2.1 with the fix, hope that helps.
@mourner thanks! Appreciate that it wasn't the solution you were looking to resolve it with. Hope things go well with the ES rewrite.
I will look at raising a PR to use 1.2.1 and closing this.
Hey guys, just to make clear, would this be an issue on @turf/concave or @turf/convex? The title of the issue and the example say two different things.
Regardless, I don't see any issue with either modules, at least not with the doc's example reported by @braco:
https://turf-sandbox.netlify.app/?gist=85c24aba86193f3542ae1493d90e986d

I think the title/text should be convex. The concaveman library is not used in concave : https://github.com/Turfjs/turf/blob/84110709afda447a686ccdf55724af6ca755c1f8/packages/turf-boolean-concave/package.json
Still, I don't see the reported error. @braco can you please post a code snippet reproducing the error?
@stebogit you would only see it if you were bundling with Webpack I think, as it's a specific issue between concaveman and Webpack
Okay update here following closing #2200 and #2200
Unfortunately we can't upgrade to concaveman 1.2.1 which fixes the issues with Queue/rbush because rbush at version 3.0.1 which is an ESM module which we can't use in turf at the moment because there is no transpiliation step. The potential solutions are:
- Vendor concaveman (not a huge fan of this for obvious reasons)
- Create a separate module as per
@turf/jstsor@turf/geojson-rbush - Kindly request concaveman uses the ES5 rbush (big ask, potentially not compatible with the maintainers needs)
- Kindly request concaveman publishes an ES5 version, similar to how
rbushis exposed underrbush/rbush(big ask)
For visibility, the concaveman dependency update will fix the content security policy issues reported in https://github.com/Turfjs/turf/issues/261, https://github.com/Turfjs/turf/issues/1903, and https://github.com/Turfjs/turf/issues/2233
because
rbushat version 3.0.1 which is an ESM module which we can't use in turf at the moment because there is no transpiliation step
Can you expand more on this? I thought Turf transpiled/bundled all dependencies, but I'm not sure how it all works in a TS ecosystem. Generally, I would love to move more of my libraries to ESM-only ES6 entry point without transpilation, leaving the ES5 transpilation on downstream users if they need legacy compatibility.