royNiladri / js-big-decimal

Work with large numbers on the client side with high precision.
https://www.npmjs.com/package/js-big-decimal
MIT License
147 stars 28 forks source link

Import errors with vite project #98

Open NiloCK opened 1 year ago

NiloCK commented 1 year ago

Describe the bug vite projects fail to consume js-big-decimal.

To Reproduce Repro repo is here: https://github.com/NiloCK/vite-bigdecimal-import-reproduction

See the readme.

Expected behavior In the repo, yarn dev should serve the sample app page, with the counter integer replaced by a bigDecimal.

Additional context The vite site seems to be mistakenly importing content from the dist/node folder, instead of dist/web

There is some issue with:

NiloCK commented 1 year ago

Response from the related issue filed vitejs/vite: https://github.com/vitejs/vite/issues/13031#issuecomment-1527404705

Quoting in full:

The bundled file is from dist/node/..., where it should be from dist/web/....

js-big-decimal doesn't declare exports/browser field and therefore Vite resolves the package with main field that points to dist/node/....

You can specify the actual file instead.

import "js-big-decimal/dist/web/js-big-decimal.js"

Although, It doesn't work because js-big-decimal doesn't support ESM.

Closing as it's working as intended.

royNiladri commented 1 year ago

@NiloCK Please validate and close this.