Closed cmdcolin closed 1 year ago
I recommend avoiding Jest because it too hacky and everything with ESM made it unusable. You can try uvu
or vitest
.
Another option is to use Jest option to change import path of nanoid
and load Node.js version (but you need to use Nano ID 3).
Another option is to use Jest option to change import path of nanoid and load Node.js version (but you need to use Nano ID 3).
is this documented by chance?
is this documented by chance?
No. It is a hacky and non-recommended way. The only non-hacky way is to migrate to ESM.
Some even bigger hacks can be found here
thank you for these examples! I will just close for now
Hi there
I am trying to use nanoid with jest with the jsdom environment, but this seems to import the specialized index.browser.js bundle, which uses pure-ESM statements, and then that causes challenges with jest when it's not configured for pure-ESM.
setting up a pure-ESM environment is hard, so I was hoping there might be a alternative solution. I would like to avoid custom jest configurations, because I want to use nanoid in a library, and don't really want my downstream users who may use jest to have to custom configure their jest either.
here is a small repro https://github.com/cmdcolin/browser-nanoid-jest-repro
this issue happens with either nanoid v3 or v4 ( can change version in the repro package.json to see)
I know these bundle/esm issues are kind of tedious, if it is too specialized a use case, can close