12.0.2 regression: can no longer import uuid package (a package with exports) with yarn pnp
See original GitHub issueWhat version of Next.js are you using?
12.0.2, 12.0.3, and 12.0.4-canary.3
What version of Node.js are you using?
16.13.0
What browser are you using?
Chrome, Safari, Vivaldi, Brave
What operating system are you using?
macOS and Windows
How are you deploying your application?
N/A (yarn dev and yarn build)
Describe the Bug
There seems to be a regression in 12.0.2 where I can no longer import the package “uuid” (and some others) when using yarn pnp. The full error looks like this:
error - unhandledRejection: Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'uuid' imported from C:\code\test-uuid-no-typescript\.next\server\pages\index.js
Did you mean to import uuid-no-typescript/.yarn/cache/uuid-npm-8.3.2-eca0baba53-5575a8a75c.zip/node_modules/uuid/dist/index.js?
error - Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'uuid' imported from C:\code\test-uuid-no-typescript\.next\server\pages\index.js
Did you mean to import uuid-no-typescript/.yarn/cache/uuid-npm-8.3.2-eca0baba53-5575a8a75c.zip/node_modules/uuid/dist/index.js?
That error text is from windows, but it’s the same on mac.
At first, https://github.com/vercel/next.js/issues/30393 seemed like it might be related, but I only started experiencing my issue in 12.0.2. If I revert to 12.0.1, everything works as expected.
I’m not sure what it is about this package that next doesn’t like. It has exports set in its package.json, but that’s not a new thing.
Expected Behavior
No error when compiling the page.
To Reproduce
$ yarn create next-app # and follow instructions
$ cd package
$ yarn set version berry && yarn config set nodeLinker pnp && yarn
$ yarn add uuid # and add an import of uuid in pages/index.js
$ yarn dev # then visit localhost:3000
Minimal reproduction: https://github.com/timmywil/test-nextjs-yarn-uuid
Note that this repo does not include typescript.
Also note that you still get this error when swc is disabled.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (4 by maintainers)
Top GitHub Comments
@timmywil I also have that issue tracked here! https://github.com/vercel/next.js/issues/31279
Not a yarn bug, it’s actually an incompatibility with custom ESM loaders and Next.js’s use of jest-worker. You can work around it by adding
experimental: { workerThreads: true }
to yournext.config.js
.@simPod I believe that has been fixed already in https://github.com/vercel/next.js/pull/33236 on
canary
. Could you test that out?@timmywil would you also give it a go with
canary
and the above recommendations to see if this is still an issue? 🙏