next.js: Next.js 13: Build failure when enabling appDir and using Yarn PnP
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64
Binaries:
Node: 18.12.0
npm: 8.19.2
Yarn: 3.2.4
pnpm: N/A
Relevant packages:
next: 13.0.2-canary.2
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
When using Yarn PnP to manage packages, running next bulid
with appDir enabled will fail to build.
The build log is:
warn - You have enabled experimental feature (appDir) in next.config.js.
warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
info - Thank you for testing `appDir` please leave your feedback at https://nextjs.link/app-feedback
warn - `enableUndici` option is unnecessary in Node.js v18.0.0 or greater.
> Build error occurred
Error: EROFS: read-only filesystem, open '/node_modules/next/dist/server/initialize-require-hook.js'
at makeError$1 (/Users/shun_shobon/tmp/my-app/.pnp.cjs:958:24)
at EROFS (/Users/shun_shobon/tmp/my-app/.pnp.cjs:985:10)
at ZipFS.prepareWriteFile (/Users/shun_shobon/tmp/my-app/.pnp.cjs:2820:13)
at ZipFS.writeFilePromise (/Users/shun_shobon/tmp/my-app/.pnp.cjs:2791:55)
at /Users/shun_shobon/tmp/my-app/.pnp.cjs:3912:26
at /Users/shun_shobon/tmp/my-app/.pnp.cjs:4136:81
at ZipOpenFS.getZipPromise (/Users/shun_shobon/tmp/my-app/.pnp.cjs:4243:22)
at ZipOpenFS.makeCallPromise (/Users/shun_shobon/tmp/my-app/.pnp.cjs:4136:23)
at ZipOpenFS.writeFilePromise (/Users/shun_shobon/tmp/my-app/.pnp.cjs:3909:23)
at VirtualFS.writeFilePromise (/Users/shun_shobon/tmp/my-app/.pnp.cjs:3219:24) {
code: 'EROFS'
}
Looking at the error log, it appears that the attempt to write in next/dist/server/initialize-require-hook.js
is failing:
https://github.com/vercel/next.js/blob/ef73798e4557a8f203f814afe0908e041b2792b2/packages/next/build/index.ts#L317-L324
Expected Behavior
No error logs are displayed and the build succeeds.
Link to reproduction
https://github.com/shun-shobon/nextjs-13-yarn-berry-build-reproduction
To Reproduce
- clone this repo
- run
yarn
to install dependencies - run
yarn build
- an error log is output and the build fails
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 33
- Comments: 16 (3 by maintainers)
Commits related to this issue
- fix: yarn unplug next to fix build refer to https://github.com/vercel/next.js/issues/42427 — committed to rjlg/nextjs-basecamp by rjlg a year ago
- unplug next until appDir and yarn pnp play nicely together https://github.com/vercel/next.js/issues/42427 — committed to toshgoodson/tosh.dev by toshgoodson a year ago
I just ran into this. A temporary workaround is to
yarn unplug next
.Bump, this really needs attention. Huge blocker for anyone using yarn 2.
This is also a problem when running ‘next build’ where node_modules is on a read only file system as is the case with some build systems.
Not a good idea for a dependency to modify its own source code when ran… Just generate this file elsewhere
We are also facing this issue with Bazel (rules_js & pnpm) when trying to enable the appDir feature. Modifying files within node_modules might work for simple setups, but can cause a lot of issues with more complex and restrictive build systems where node_modules is on a read only file system (for example to avoid any side effects when sharing dependencies between build agents and for guaranteeing hermetic builds).
It looks like this was introduced in #41687
@huozhi @ijjk would it be possible to maybe move this file to the
.next
output folder or avoid writing it in node_modules in another way, e.g. by checking if the appDir feature is enabled differently? I am also happy to contribute if there is a common agreement on how this should be fixed.Looks like this fixed for us (with @cyrilwanner) Bazel with rules_js & pnpm, from
next@13.4.1
. 👍@bryanjtc, this is unrelated to Yarn PnP. I’ve reported this issue with some background and a workaround (enable
typedRoutes
experimental feature) in https://github.com/vercel/next.js/issues/49004