josdejong / lossless-json

Parse JSON without risk of losing numeric information
MIT License
430 stars 28 forks source link

configure `exports` in `package.json` to fix problem with Jest #243

Closed akphi closed 2 years ago

akphi commented 2 years ago

@josdejong Thank you so much for finding the time to make the transition to ESM. After upgrading, we got some problem running test with Jest, the symptom is very similar to what observed in

https://github.com/uuidjs/uuid/issues/451 and https://github.com/uuidjs/uuid/pull/616

In summary, when jest-resolve fail to find commonjs bundle and always pick ESM bundle. We're still running Jest in non-ESM mode and I believe a lot of project still do at the moment, so this would be a great help if we could provide a fix.

I have tried the update the package.json file to use exports and this resolves the problem on my end. Could you find the time to review and release this change?


For those who faced the same issue, the workaround is to transform lossless-json using babel-jest (for example) by excluding from the transform ignore list.

josdejong commented 2 years ago

Thanks for your PR An Phi 👍 . Makes sense to add an exports field.

josdejong commented 2 years ago

Fix is now published in v2.0.1