-
-
Notifications
You must be signed in to change notification settings - Fork 910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Cannot use uuid with Jest #640
Comments
I have the same issue. Started with Jest@28. I'm using uuid in a private library where Jest works fine. However, that private library, when used as a dependency in a project reproduces the error reported. Other library ESM dependencies work as expected. |
This may be a problem with Jest (they changed Babel configuration in v28). It seems that Jest does not transform the uuid dependency. The following workaround in jest.config got tests passing for me:
|
Thanks for the message John. Also might I just further ask - why is this necessary? I thought by default all of node_modules is ignored anyway? Thanks for the help! |
This was in my own project. The thinking was to get Jest to transform that node_module - so it ends up as a commonjs module which Jest was expecting. Sorry that didn't work for you. |
Ah makes sense, thanks for clarifying. still pretty new to JS ecosystem! |
Jest is pulling in the "default" ESModules export, which only has experimental support in Jest you need to opt into. Is it possible to add a
|
wow! this fixed it. Only issue with this approach is this is going to get deleted whenever I delete/reinstall node_modules, and probably when I update packages. |
For anyone else looking for a fix for this, this PR solves it: https://github.com/uuidjs/uuid/pull/616/files Also a better fix, that worked for me, that doesnt require changing something in node_modules (so will persist through reinstalling your node_modules): #451 (comment) |
Thanks |
Would it be possible to release a |
Unfortunately supporting jest out of the box was technically a breaking change for this library as we added a CommonJS browser build that users receive who previously received an ESM build. As far as I know the change to jest that broke interoperability with uuid also got introduced with a major version bump of jest, so I think this is working as intended. |
For me a combination of the suggestions by @chrisahardie and @kikoanis was the fix:
Tip: If you are manually creating your patch, by default Additional tip: If your CI/CD builds Docker images for test runs, make sure the Patch `./patches/uuid+8.3.2.patch`diff --git a/node_modules/uuid/package.json b/node_modules/uuid/package.json
index f0ab371..0561718 100644
--- a/node_modules/uuid/package.json
+++ b/node_modules/uuid/package.json
@@ -20,6 +20,7 @@
"main": "./dist/index.js",
"exports": {
".": {
+ "require": "./dist/index.js",
"node": {
"module": "./dist/esm-node/index.js",
"require": "./dist/index.js", |
Before you begin...
Description of the problem
When I import the aws-sdk/client-dynamodb (which uses uuid), I can no longer test with the latest version of Jest.
Recipe for reproducing
Additional information
I also raised an issue in Next.js but got redirected here: vercel/next.js#38368
Environment
The text was updated successfully, but these errors were encountered: