turf icon indicating copy to clipboard operation
turf copied to clipboard

Bundling @turf/convex with Webpack not working due to concaveman dependency

Open braco opened this issue 4 years ago • 11 comments

@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);

braco avatar Aug 08 '21 16:08 braco

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.

JamesLMilner avatar Aug 08 '21 21:08 JamesLMilner

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.

braco avatar Aug 09 '21 06:08 braco

Released concaveman v1.2.1 with the fix, hope that helps.

mourner avatar Aug 09 '21 09:08 mourner

@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.

JamesLMilner avatar Aug 09 '21 15:08 JamesLMilner

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 Screen Shot 2021-08-09 at 9 28 15 AM

stebogit avatar Aug 09 '21 16:08 stebogit

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

JamesLMilner avatar Aug 09 '21 17:08 JamesLMilner

Still, I don't see the reported error. @braco can you please post a code snippet reproducing the error?

stebogit avatar Aug 09 '21 17:08 stebogit

@stebogit you would only see it if you were bundling with Webpack I think, as it's a specific issue between concaveman and Webpack

JamesLMilner avatar Aug 09 '21 20:08 JamesLMilner

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/jsts or @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 rbush is exposed under rbush/rbush (big ask)

JamesLMilner avatar Dec 05 '21 19:12 JamesLMilner

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

cjhewett avatar Dec 06 '21 09:12 cjhewett

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

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.

mourner avatar Dec 06 '21 09:12 mourner