Skip to content

Next.js 13: Build failure when enabling appDir and using Yarn PnP #42427

Closed
@shun-shobon

Description

@shun-shobon

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:

await promises
.writeFile(
initialRequireHookFilePath,
content.replace(
/isPrebundled = (true|false)/,
`isPrebundled = ${isAppDirEnabled}`
)
)

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

NEXT-1378

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue was opened via the bug report template.linear: nextConfirmed issue that is tracked by the Next.js team.locked

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions