Skip to content

fix(nextjs): reset daemon client after project graph creation in withNx#34518

Merged
FrozenPandaz merged 1 commit intomasterfrom
issue-32880
Feb 20, 2026
Merged

fix(nextjs): reset daemon client after project graph creation in withNx#34518
FrozenPandaz merged 1 commit intomasterfrom
issue-32880

Conversation

@jaysoo
Copy link
Copy Markdown
Member

@jaysoo jaysoo commented Feb 19, 2026

Current Behavior

Running nx test for Next.js projects causes Jest to hang with:

Jest did not exit one second after the test run has completed.

This happens because next/jest loads next.config.js, which calls withNxcreateProjectGraphAsync(). The daemon client socket connection is left open, keeping the Node.js event loop alive and preventing Jest from exiting. Non-Next.js projects are unaffected since they don't trigger this code path.

Expected Behavior

Jest exits cleanly after tests complete for Next.js projects, without needing forceExit: true.

Fix

Pass resetDaemonClient: true to createProjectGraphAsync() in packages/next/plugins/with-nx.ts. This tells the project graph function to call daemonClient.reset() after fetching the graph, which closes the socket and allows Jest to exit.

Verification

Scenario Before After
nx test next-app Hangs Exits cleanly
NX_DAEMON=false nx test next-app Exits cleanly Exits cleanly
Direct npx jest Exits cleanly Exits cleanly
Non-Next.js nx test react-lib Exits cleanly Exits cleanly

Related Issue(s)

Fixes #32880

@jaysoo jaysoo requested a review from a team as a code owner February 19, 2026 18:33
@jaysoo jaysoo requested a review from Coly010 February 19, 2026 18:33
@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Feb 19, 2026

View your CI Pipeline Execution ↗ for commit 0801a4b

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 12m 5s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2m 43s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 8s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded <1s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-19 21:03:29 UTC

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 19, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit 0801a4b
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/699776c8891eda00084f9635
😎 Deploy Preview https://deploy-preview-34518--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Feb 19, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit 0801a4b
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/699776c84db2de000882cb2e
😎 Deploy Preview https://deploy-preview-34518--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

nx-cloud[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud has identified a possible root cause for your failed CI:

Our investigation shows this test failure is pre-existing in the master branch and unrelated to the daemon client reset changes. The error stems from a missing ESM submodule in @microsoft/api-extractor during Vite config processing, which has no connection to the Next.js withNx modifications in this PR.

No code changes were suggested for this issue.

Trigger a rerun:

Rerun CI

Nx Cloud View detailed reasoning on Nx Cloud ↗


🎓 Learn more about Self-Healing CI on nx.dev

## Current Behavior

Running `nx test` for Next.js projects causes Jest to hang with:
"Jest did not exit one second after the test run has completed."

This happens because `next/jest` loads `next.config.js`, which calls
`withNx` → `createProjectGraphAsync()`. The daemon client socket
connection is left open, keeping the Node.js event loop alive and
preventing Jest from exiting.

## Expected Behavior

Jest exits cleanly after tests complete for Next.js projects.

## Related Issue(s)

Fixes #32880
@AgentEnder
Copy link
Copy Markdown
Member

This should be fixed after #34506, I don't think this ones needed?

@jaysoo
Copy link
Copy Markdown
Member Author

jaysoo commented Feb 20, 2026

This should be fixed after #34506, I don't think this ones needed?

Hmm, will test after that change lands.

@FrozenPandaz FrozenPandaz merged commit de2dc7c into master Feb 20, 2026
23 checks passed
@FrozenPandaz FrozenPandaz deleted the issue-32880 branch February 20, 2026 16:08
FrozenPandaz pushed a commit that referenced this pull request Feb 20, 2026
…Nx (#34518)

## Current Behavior

Running `nx test` for Next.js projects causes Jest to hang with:
```
Jest did not exit one second after the test run has completed.
```

This happens because `next/jest` loads `next.config.js`, which calls
`withNx` → `createProjectGraphAsync()`. The daemon client socket
connection is left open, keeping the Node.js event loop alive and
preventing Jest from exiting. Non-Next.js projects are unaffected since
they don't trigger this code path.

## Expected Behavior

Jest exits cleanly after tests complete for Next.js projects, without
needing `forceExit: true`.

## Fix

Pass `resetDaemonClient: true` to `createProjectGraphAsync()` in
`packages/next/plugins/with-nx.ts`. This tells the project graph
function to call `daemonClient.reset()` after fetching the graph, which
closes the socket and allows Jest to exit.

### Verification

| Scenario | Before | After |
|----------|--------|-------|
| `nx test next-app` | Hangs | Exits cleanly |
| `NX_DAEMON=false nx test next-app` | Exits cleanly | Exits cleanly |
| Direct `npx jest` | Exits cleanly | Exits cleanly |
| Non-Next.js `nx test react-lib` | Exits cleanly | Exits cleanly |

## Related Issue(s)

Fixes #32880

(cherry picked from commit de2dc7c)
llwt pushed a commit that referenced this pull request Feb 23, 2026
…Nx (#34518)

## Current Behavior

Running `nx test` for Next.js projects causes Jest to hang with:
```
Jest did not exit one second after the test run has completed.
```

This happens because `next/jest` loads `next.config.js`, which calls
`withNx` → `createProjectGraphAsync()`. The daemon client socket
connection is left open, keeping the Node.js event loop alive and
preventing Jest from exiting. Non-Next.js projects are unaffected since
they don't trigger this code path.

## Expected Behavior

Jest exits cleanly after tests complete for Next.js projects, without
needing `forceExit: true`.

## Fix

Pass `resetDaemonClient: true` to `createProjectGraphAsync()` in
`packages/next/plugins/with-nx.ts`. This tells the project graph
function to call `daemonClient.reset()` after fetching the graph, which
closes the socket and allows Jest to exit.

### Verification

| Scenario | Before | After |
|----------|--------|-------|
| `nx test next-app` | Hangs | Exits cleanly |
| `NX_DAEMON=false nx test next-app` | Exits cleanly | Exits cleanly |
| Direct `npx jest` | Exits cleanly | Exits cleanly |
| Non-Next.js `nx test react-lib` | Exits cleanly | Exits cleanly |

## Related Issue(s)

Fixes #32880
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Feb 26, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Next test using Jest does not exit

3 participants