nanoid: TypeError: (0 , _nanoid.nanoid) is not a function on v3.3.1
I have just installed latest nanoid (to replace the heavier uuid
package on a webpack-based web app), and it seems to work fine at build time and runtime, but when running the tests with jest, it does not seem to properly resolve the module, resulting in TypeError: (0 , _nanoid.nanoid) is not a function
.
I have seen this was already reported here https://github.com/ai/nanoid/issues/205, but I have tried every workaround proposed there and none of them seem to work now. Since that issue is a bit old, maybe the error is back with a different root cause this time.
I have also tried using jest’s moduleNameMapper
to manually map to one of the modules from this package. I have tried index.js
, index.cjs
, index.browser.js
and index.browser.cjs
, and also, none of them fix the error.
The errors can be seen here https://github.com/shlinkio/shlink-web-client/runs/5708689479?check_suite_focus=true
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (4 by maintainers)
The solution I found was not to use the latest version (4.x) and use a 3.x.x and that’s it
moduleNameMapper
is not enough.Try to create custom resolver https://github.com/facebook/jest/issues/9771#issuecomment-974750103