Skip to content

Build error occurs with large number of files in pages directory: spawn EBADF #78276

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

Open
Sarawut-keng opened this issue Apr 17, 2025 · 4 comments
Labels
Output Related to the the output configuration option.

Comments

@Sarawut-keng
Copy link

Sarawut-keng commented Apr 17, 2025

Link to the code that reproduces this issue

https://github.com/Sarawut-keng/nextjs-build-error-reproduction

To Reproduce

  1. Clone the reproduction repository: https://github.com/Sarawut-keng/nextjs-build-error-reproduction
  2. Install dependencies
  3. Run next build
  4. Observe the build failure with the EBADF spawn error after "Collecting page data" step

Note that the issue is more severe in my private project which contains more files and greater complexity.

Current vs. Expected behavior

Expected Behavior

Next.js should successfully build the project regardless of the number of files and folders in the pages directory, with appropriate resource management.

Actual Behavior

The build process fails after successfully completing the "Collecting page data" step:

✓ Linting and checking validity of types    
    Creating an optimized production build ...
✓ Compiled successfully in 14.0s
✓ Collecting page data    

> Build error occurred
[Error: spawn EBADF] { errno: -9, code: 'EBADF', syscall: 'spawn' }

This indicates the build process completes compilation and page data collection successfully, but fails when attempting to proceed to the next step.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.5.0: Wed May  1 20:19:05 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T8112
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.14.0
  npm: 10.9.2
  Yarn: 1.22.21
  pnpm: N/A
Relevant Packages:
  next: 15.3.1-canary.11 // Latest available version is detected (15.3.1-canary.11).
  eslint-config-next: 15.3.0
  react: 19.1.0
  react-dom: 19.1.0
  typescript: 5.8.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Output

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

System Information

  • Next.js version: ^15.3.1-canary.11
  • Operating System: macOS (MacBook Pro M2)
  • Node.js version: v22.14.0
  • Package Manager and version: npm 10.9.2

Additional Information

The timing of the error (after successfully collecting page data) suggests that the issue may occur during the optimization or bundling phase, when Next.js attempts to process all the collected pages simultaneously.
This appears to be a regression issue. I've tested the following versions:

  • Next.js 15.3.0: Error still occurs
  • Next.js 14.2.28: Builds successfully with the same number of files

The problem seems to have been introduced in version 15.x of Next.js, as version 14.2.28 handles the same project structure without errors.

@github-actions github-actions bot added the Output Related to the the output configuration option. label Apr 17, 2025
@Jsurapong
Copy link

i have the same mistake
run yarn build

▲ Next.js 15.3.0
   - Environments: .env

   Skipping linting
 ✓ Checking validity of types    
   Creating an optimized production build ...
 ✓ Compiled successfully in 23.0s
 ✓ Collecting page data    

> Build error occurred
[Error: spawn EBADF] { errno: -9, code: 'EBADF', syscall: 'spawn' }

@wuguoguang
Copy link

I had the same problem when building, how could I fix it?

@Sarawut-keng
Copy link
Author

I had the same problem when building, how could I fix it?

@wuguoguang There’s no proper solution yet. For now, I just downgraded to version 14.2.28 and it works fine. I’ll stick with it until there’s a fix or a better solution comes along.

@Code-Divine
Copy link

I hope nextjs team takes this issue with greater urgency. We have the same exact issue as reported. It happens since first 15.0 version. We have 150 pages in our project and this same issue happens. If I delete half the pages, it builds without issue. The app is working great otherwise, just can't build it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Output Related to the the output configuration option.
Projects
None yet
Development

No branches or pull requests

4 participants