next.js: `next dev` and `next build` broken on Yarn PnP in the latest release
What version of Next.js are you using?
v12.0.5
What version of Node.js are you using?
v16.13.1
What browser are you using?
N/A
What operating system are you using?
Windows 11 (Build 22509.1000)
How are you deploying your application?
yarn next build && yarn next start
Describe the Bug
Getting the following errors on running yarn next build
:
$ yarn next build
info - Checking validity of types
warn - No ESLint configuration detected. Run next lint to begin setup
info - Creating an optimized production build
Failed to compile.
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/index.js
Error: Failed to read source code from C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\client\index.js
Caused by:
The system cannot find the path specified. (os error 3)
Import trace for requested module:
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/next.js
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/request-idle-callback.js
Error: Failed to read source code from C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\client\request-idle-callback.js
Caused by:
The system cannot find the path specified. (os error 3)
Import trace for requested module:
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/route-loader.js
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/shared/lib/router/router.js
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/router.js
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/pages/_app.js
Error: Failed to read source code from C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\pages\_app.js
Caused by:
The system cannot find the path specified. (os error 3)
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/shared/lib/head.js
Error: Failed to read source code from C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\shared\lib\head.js
Caused by:
The system cannot find the path specified. (os error 3)
Import trace for requested module:
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/pages/_error.js
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/shared/lib/mitt.js
Error: Failed to read source code from C:\Users\brc-dd\Desktop\foo\.yarn\__virtual__\next-virtual-fedb67b0ce\0\cache\next-npm-12.0.5-1c991f073c-616235e394.zip\node_modules\next\dist\shared\lib\mitt.js
Caused by:
The system cannot find the path specified. (os error 3)
Import trace for requested module:
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/shared/lib/router/router.js
./.yarn/__virtual__/next-virtual-fedb67b0ce/0/cache/next-npm-12.0.5-1c991f073c-616235e394.zip/node_modules/next/dist/client/router.js
> Build failed because of webpack errors
The issue seems to be SWC related. After creating .babelrc
with next/babel
preset, the yarn next build
command is working but yarn next dev
is still throwing error.
Also, why the Checking validity of types
log is shown even if someone is not using TS?
Expected Behavior
To build successfully and start as happens in next@12.0.4
.
To Reproduce
mkdir foo && cd "$_"
yarn init -2
yarn add next react react-dom
mkdir pages
echo 'export default () => <div>Hello World</div>' > pages/index.js
yarn next build
Based on https://github.com/yarnpkg/berry/blob/master/.github/workflows/e2e-next-workflow.yml
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 38
- Comments: 19 (6 by maintainers)
Commits related to this issue
- Unplug react-dom (workaround for vercel/next.js#32115) — committed to ciffelia/og-image by ciffelia 3 years ago
- Fix broken yarn pnp (#32867) x-ref [#31552 ](https://github.com/vercel/next.js/issues/31552) x-ref https://github.com/vercel/next.js/issues/32115 x-ref https://github.com/vercel/next.js/issues/32546... — committed to vercel/next.js by kaykdm 2 years ago
- Fix broken yarn pnp (#32867) x-ref [#31552 ](https://github.com/vercel/next.js/issues/31552) x-ref https://github.com/vercel/next.js/issues/32115 x-ref https://github.com/vercel/next.js/issues/32546... — committed to natew/next.js by kaykdm 2 years ago
@timneutkens
next build
is working after setting that, butnext dev
is still throwing errors:PS: This is happening since
v12.0.5-canary.0
.Related Issues - #31552, #31812
This prevents me from using Next.js >= v12.0.5.
Edit: node v16.13.1, macOS 12.0.1
@dgattey that option has been recently changed to accommodate your use case in #33236 we will include it in the next upcoming
canary
release (which is 🔜™️), thanks for the feedback! 👍Version 12.0.4 is the highest version I could go without this error.
For now, if anyone is facing the issue with
next dev
, try unpluggingreact-dom
(yarn unplug react-dom
), it should work (although in a way this defeats the purpose of zero-installs).@taavisalo Have you added
swcFileReading: false,
toexperimental
? Setting it in the root object doesn’t work, but inexperimental
I was able to fix this issue.Thank you! Running yarn cache clear fixed the problem.
EDIT: yarn dev works, but yarn build still fails with “Error: Failed to read source code” errors.
@taavisalo see here: https://github.com/vercel/next.js/pull/32867#issuecomment-1010860894
@timneutkens @sokra
I just opened PR to fix this https://github.com/vercel/next.js/pull/32867
@brc-dd Thanks for the hint, unplugging react query “fixes” my error above. But I agree, unplugging should not be the solution for this issue. I’m staying on 12.0.5 for now until we have a proper fix 😃