Conversation
|
I'm trying to migrate from CommonJS to ES Modules and this issue is getting in the way. I'm seeing errors like the following on Manually applying the changes from this pull request in @MikeMcl Any hesitation about merging this? I'm happy to help in any way I can. |
|
It doesn't feel right to add a new file to the project, I think I would prefer to get rid of the type definition files and get AI assistance to add the type definitions as JSDoc comments in the bignumber.js and bignumber.mjs files. Any thoughts? |
|
I don't think there's anything wrong with shipping two type files, they are technically for different environments (CJS and ESM) 😄 |
|
It's a bigger npm module. Anyway, I need more time to look at his. I haven't seen that tool before and it's not clear what configuration etc. is being used. |
|
The size addition would just be the type file so wouldn't effect anyone's compiled code, happy to answer any questions that you have |
|
Apparently, the |
Sorry I don't fully understand what you mean, I went to the master branch and added I'm fine with the solution being anything, what I opened a PR with is what I got |
|
Thanks for testing that. I think the current type definitions (not this PR) rely on |
Good point, I hadn't thought about this. Maybe we could introduce two new entrypoints,
This approach would still require you to compile and ship |
Yes, good idea, but it may get quite complex as there is also a class, namespace and function to be exported. I take the point you make about similar duplication. I'll probably accept this PR soon but I am just reacquainting myself with this stuff first, as I don't like accepting changes I don't fully understand. |
|
This is a very important library to the ecosystem so please take all the time you need to feel comfortable, thank you for making this! I have similar PRs for your other repositories as well: |
|
@MikeMcl Have you had a chance to consider whether you'd like to merge this change or not? |
@MikeMcl hey I haven't tested it but 9.2.0 might be breaking people "A require call resolved to an ESM JavaScript file, which is an error in Node and some bundlers. CommonJS consumers will need to use a dynamic import." https://arethetypeswrong.github.io/?p=bignumber.js%409.2.0 |
|
That warning is due to the presence of the Noone is likely to choose to use require to import from that ES module when they can just as easily use the bignumber/bignumber.js subpath to require the CommonJS version. I could remove the subpath exports and the warning goes away but it means it would probably break someone's code, and it makes the package less flexible. |
|
types break when i used this, which is due to the PR this works well |
|
Thanks for the report. I noticed that too but I have no firm conclusions about it yet. |
|
Hopefully, fixed in v9.2.1, so named import should now work again. |
https://arethetypeswrong.github.io/?p=bignumber.js%409.1.2
Fix imports and types by copying
bignumber.d.tstobignumber.d.mts.Test with:
npx @arethetypeswrong/cli@latest --pack .