Commit Graph

5 Commits

Author SHA1 Message Date
Jimmy Lai cb0d88f6e3 Improve existing dev server error message to suggest using it (#92317)
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
### What?

Improves the error message shown when a user tries to start `next dev`
while another dev server is already running in the same directory.

### Why?

Previously, the error message only suggested killing the existing
process (`Run kill <pid> to stop it.`). This wasn't the best advice —
often the user just wants to access the already-running dev server
rather than kill it and start a new one.

### How?

Updated the error message in `packages/next/src/build/lockfile.ts` to
present both options:

1. Access the existing server at its URL
2. Kill the process if they want to start a new one

**Before:**
```
✖ Another next dev server is already running.

- Local:        http://localhost:3000
- PID:          61479
- Dir:          /path/to/project
- Log:          .next/dev/logs/next-development.log

Run kill 61479 to stop it.
```

**After:**
```
✖ Another next dev server is already running.

- Local:        http://localhost:3000
- PID:          61479
- Dir:          /path/to/project
- Log:          .next/dev/logs/next-development.log

You can access the existing server at http://localhost:3000,
or run kill 61479 to stop it and start a new one.
```

Updated the lockfile test regex to match the new message format.
<!-- CURSOR_AGENT_PR_BODY_END -->

[Slack
Thread](https://vercel.slack.com/archives/C046HAU4H7F/p1775173304387809?thread_ts=1775173304.387809&cid=C046HAU4H7F)

<div><a
href="https://cursor.com/agents/bc-0bb3085b-1fd1-56c3-8617-cd8a32d8c376"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-0bb3085b-1fd1-56c3-8617-cd8a32d8c376"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-04-03 16:33:13 -07:00
Jiachi Liu af18c32bc8 Improve lock dir error message (#89119) 2026-01-30 16:38:25 +01:00
Benjamin Woodruff 167608775c fix(experimental.lockDistDir): Acquire the lock in dev earlier (#85116)
Apparently I grabbed the lock too late, which led to the second process still managing the `distDir` before exiting... https://vercel.slack.com/archives/C03EWR7LGEN/p1760910025067089

This moves the acquisition earlier for dev, and extends the e2e test to cover this.

[Screen Recording 2025-10-20 at 10.42.49 AM.webm <span class="graphite__hidden">(uploaded via Graphite)</span> <img class="graphite__hidden" src="https://app.graphite.dev/user-attachments/thumbnails/68785bda-1dd5-437a-bf16-54de2d54a49c.webm" />](https://app.graphite.dev/user-attachments/video/68785bda-1dd5-437a-bf16-54de2d54a49c.webm)
2025-10-20 14:25:51 -07:00
Benjamin Woodruff 61a8037835 Rspack: Fix lockfile test on rspack (#84707)
Noticed this on https://github.com/vercel/next.js/pull/84673

We don't run rspack test on every PR, so this wasn't caught before.
2025-10-09 17:28:04 -07:00
Benjamin Woodruff 0b74ff9b2b feat: Acquire a lockfile on distDir in next dev and next build (#84428)
https://github.com/vercel/next.js/pull/83961 lets you run both `next dev` and `next build` at the same time, however it's still problematic to run two instances of `next dev` or two instances of `next build` at the same time with the same `distDir`.

This sort of thing can happen to anyone by accident, but we've seen reports of this sort of behavior with AI agents.

https://github.com/vercel/next.js/pull/84378 adds a lockfile around just the persistent cache database in Turbopack, which helps, but it's not the only reason this is problematic, so we also need a lock around all of Next.js itself.

I was not able to find a cross-platform lockfile implementation in node that I felt was of sufficient quality, so on POSIX platforms this uses the recently-stabilized Rust stdlib implementation, which appears to be derived from rustc's own lockfile implementation, which has seen widespread use/deployment.

On Windows, since we'd rather have an advisory lock than a mandatory one, this emulates that by instead opening a file with write permissions, and a sharing mode that prohibits shared write access. That means that other processes can safely read the (empty) lockfile without blowing up.

<img width="500" src="https://github.com/user-attachments/assets/1ee4a6c6-2280-4f64-8bf2-ec5369c26db1" />
<img width="500" src="https://github.com/user-attachments/assets/2b04b566-c0b4-42ce-af34-912f3f6afa72" />

Tested on Windows as well:

<img width="1224" height="690" alt="Screenshot 2025-10-07 at 5 44 33 PM" src="https://github.com/user-attachments/assets/e36085b6-9c32-40ac-aca6-4c83e2a53842" />
2025-10-08 10:52:17 -07:00