Closed leite08 closed 1 year ago
Thank you for the request. The age of dual packaging seems to be over, and many libraries are migrating to the pure ESM arrangement. I'm currently not planning to reintroduce a CJS entry point.
Thanks for the response and for building this!
Hitting this issue as well. @leite08 would you mind sharing the approach you ended up taking, if any?
It would be great if you could reconsider supporting CJS as well @LiosK, I don't think the ecosystem is there yet in terms of ESM support and this could inhibit adoption of your awesome library
Let's see if other similar requests will come.
@reecefenwick we just ended up copying the index.ts file.
Other attempts (mainly make our project ESM-only) led to other libraries CJS-only to break.
I ended up using https://github.com/jetpack-io/typeid-js as it was more of a complete solution for what I was doing, but it uses this library under the hood so thanks for your work @LiosK !
I'm also facing this issue. I also ended up copying the file locally, but it makes upgrades harder :). Would love it to be exported as CommonJS as well.
v0.6 reintroduced the CommonJS entry point! However, I will remove it once this library reaches the stable release (v1.0). I am planning to make the last unstable release (v0.x) functionally equivalent to v1.0 except the CommonJS export, so that those who want the CJS support can stay with that unstable release, but no new feature will be offered to CJS users.
Currently this project exports ESM packages on NPM. It would be useful to have CJS exported as well for projects that rely on that format.
Our Use Case
In our setup, we transpile our Typescript code into CJS. After installing
uuidv7
from NPM the transpilation works fine (tsc
), but we couldn't make our Jest to work.We get
SyntaxError: Unexpected token 'export'
because out setup is for CJS, but the imported source fromuuidv7
is ESM.If we take the route to adjust our setup to ESM [1, 2] this goes away, but a bunch of other stuff break.
Proposed Solution
tsconfig
files, one for CJS and another for ESM;build
script to transpile twice, once for eachtsconfig
;package.json
to exportimports
to the ESMdist
folder andrequires
to the CJSdist
folder.Source: https://www.sensedeep.com/blog/posts/2021/how-to-create-single-source-npm-module.html