mourner / kdbush

A fast static index for 2D points
ISC License
637 stars 69 forks source link

Missing CJS #39

Closed dnohr closed 4 months ago

dnohr commented 1 year ago

Hi,

Thank you for working on the project, I really appreciate it.

I was updating all my libraries as usual, but it seems like the new v4.0.1 doesn't work with Common JS anymore. Is this intentional or is it a bug? I had to roll back to version 3.0.0, which works as intended.

Thank you!

mourner commented 1 year ago

Ah, yeah, I forgot to mention that I dropped the CommonJS entry point — I did the same with Flatbush a year ago and no one mentioned it. Is it still a deal breaker now that Node versions which don't support ESM have long reached End of Life?

dnohr commented 1 year ago

Thank you for replying so quickly!

I am utilizing this module in larger web projects, which makes it difficult to alter the codebase to ESM. Although I aimed to use the updated version, I'm uncertain about the effort required to make it compatible with both CJS and ESM.

It would have been much simpler for everyone if imports worked immediately within CommonJS. Thanks.

ChrisLahaye commented 1 year ago

Would it be possible to support CommonJS?

dnohr commented 8 months ago

This is still a wish for 2024, as it's still the fastest algorithm for its task of doing nearby searches. If you have any guidance for enabling CommonJS without additional work from your side, I'm all ears. Thank you again for working on the library!

mourner commented 8 months ago

@dnohr the easiest approach is to just use KDBush v3 and not upgrade further. Another option is to use a dynamic import within a CommonJS module — await import('kdbush').

dnohr commented 8 months ago

@mourner: Yeah, I'm using v3 now, but since I'm using the ncu update script, I manually need to downgrade it to v3 again. It's not a big thing, but I still wish CommonJS was supported in the newest versions. Do you have any working examples of using kdbush with dynamic import? I tried, but it keeps failing within my CommonJS project.

mspanc commented 6 months ago

It seems it causes some issues with TypeScript. It tends to rewrite imports in such a way that you need to use hacks to use the library: https://github.com/microsoft/TypeScript/issues/43329#issuecomment-1635074246

Given that it seems it would have been nicer to have CJS entrypoint.

mourner commented 4 months ago

Closing this issue since I no longer intend to support CommonJS in any of my projects. Please let this thing die already, the faster everyone moves on the better for the JS ecosystem 🙏