FG
๐ŸŒ Web & Full-StackVercel

Hight number of processes of /next/dist/compiled/jest-worker/processChild.js still alive after next build

Freshabout 21 hours ago
Mar 14, 20260 views
Confidence Score92%
92%

Problem

Verify canary release - [X] I verified that the issue exists in the latest Next.js canary release Provide environment information Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 22.3.0: Thu Jan 5 20:48:54 PST 2023; root:xnu-8792.81.2~2/RELEASE_ARM64_T6000 Binaries: Node: 18.13.0 npm: 8.19.3 Yarn: 1.22.19 pnpm: 7.26.2 Relevant packages: next: 12.0.9 react: 17.0.2 react-dom: 17.0.2 Which area(s) of Next.js are affected? (leave empty if unsure) CLI (create-next-app) Link to the code that reproduces this issue https://github.com/vercel/next.js/files/10565355/reproduce.zip To Reproduce reproduce.zip <img width="1492" alt="image" src="https://user-images.githubusercontent.com/3240259/216242566-6f87ae6e-e369-405f-9fca-e525e051797d.png"> This problem can reproduce above next@12.0.9, but 12.0.8 was all right. Or remove `getInitialProps` in `_app.tsx ` was all right above next@12.0.9. [code block] Describe the Bug Hight number of processes of /next/dist/compiled/jest-worker/processChild.js still alive after next build Expected Behavior Kill all child processes. Which browser are you using? (if relevant) _No response_ How are you deploying your application? (if relevant) _No response_ <sub>NEXT-1348</sub>

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Terminate Stale Child Processes in Next.js Build

Medium Risk

The issue arises due to a bug in Next.js version 12.0.9 where child processes spawned by jest-worker are not being terminated properly after a build. This can lead to resource exhaustion and unexpected behavior during subsequent builds.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Upgrade Next.js to Latest Version

    Upgrade Next.js to the latest stable version where the issue has been fixed. This is the most straightforward solution to ensure that any bugs related to process management are resolved.

    bash
    npm install next@latest
  2. 2

    Modify Build Script to Force Kill Processes

    If upgrading is not feasible, modify the build script to explicitly kill any remaining child processes after the build completes. This can be done by adding a cleanup step in your build process.

    javascript
    const { exec } = require('child_process'); exec('pkill -f processChild.js');
  3. 3

    Remove getInitialProps from _app.tsx

    As a temporary workaround, remove or refactor the use of `getInitialProps` in `_app.tsx`, as it has been observed that this can alleviate the issue with child processes not terminating.

    typescript
    export default function MyApp({ Component, pageProps }) { return <Component {...pageProps} />; }
  4. 4

    Monitor Process Usage

    After implementing the above changes, monitor the process usage during and after the build to ensure that no stale processes remain. Use tools like `htop` or `ps` to check for lingering processes.

    bash
    ps aux | grep processChild.js
  5. 5

    Report Back to Next.js Team

    If the issue persists even after applying the fixes, gather logs and process information, and report back to the Next.js team for further investigation.

    bash
    npx next build > build-log.txt; cat build-log.txt

Validation

Confirm the fix by running the build process multiple times and checking that no processes related to processChild.js remain alive after completion. Use `ps aux | grep processChild.js` to verify.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

nextjsreactssrplease-add-a-complete-reproductionbuglinear:-next