with one click
nextjs-local-preview-locks
// Safely start and verify a Next.js local preview when existing dev servers, occupied ports, or .next/dev lock files cause stale or misleading results.
// Safely start and verify a Next.js local preview when existing dev servers, occupied ports, or .next/dev lock files cause stale or misleading results.
[HINT] Download the complete skill directory including SKILL.md and all related files
| name | nextjs-local-preview-locks |
| description | Safely start and verify a Next.js local preview when existing dev servers, occupied ports, or .next/dev lock files cause stale or misleading results. |
| version | 1.0.0 |
| author | Hermes Agent |
| license | MIT |
| metadata | {"hermes":{"tags":["nextjs","local-preview","dev-server","troubleshooting","verification"]}} |
Use this when a repo needs a local preview but next dev is blocked by an existing server, stale page content on port 3000, or Unable to acquire lock at .next/dev/lock.
npm run dev appears to work, but browser content does not match the current repoEADDRINUSEUnable to acquire lock at .../.next/dev/locklocalhost:3000 can accidentally hit an unrelated or stale dev server.next dev instance may fail even on a different port because Next.js holds a repo-local dev lock under .next/dev/lock.next start serves the last completed production build, not your current source tree. If you changed code after the previous build, the browser can keep showing an older page until you run npm run build again and restart the next start process.lsof -nP -iTCP:3000 -sTCP:LISTEN
If the page looks wrong, do not assume the current repo owns that port.
Then verify which checkout actually owns that listener before trusting any browser result:
ps -p <PID> -o pid=,ppid=,command=
lsof -p <PID> | grep ' cwd '
Why:
node_modules symlink over a full reinstall when you only need a short-lived dev previewIf the root checkout already has dependencies installed and the user wants to avoid repeated installs inside worktrees, a fast-path is:
ln -s /path/to/root-checkout/node_modules node_modules
npm run dev -- --port 3456
Why:
npm run dev -- --port 3456
Prefer the CLI flag form above for Next.js. It is explicit and easy to verify in logs.
Find and stop the existing same-repo dev process before retrying. If you started it through Hermes with terminal(background=true), kill that tracked process first.
Then restart:
npm run dev -- --port 3456
next start, rebuild before trusting the browserAfter any source change:
npm run build
Then stop the old next start process and restart it:
npm run start -- --port 3456
Why:
next start serves the previous build output until you rebuild.When comparing a live page and a local preview of a long static marketing page:
browser_console, such as:
getBoundingClientRect())Useful patterns:
Array.from(document.querySelectorAll('main h2, main h3')).map((h) => {
const r = h.getBoundingClientRect();
return { text: h.textContent?.trim(), left: Math.round(r.left), top: Math.round(r.top + window.scrollY) };
})
Array.from(document.images).map((img) => {
const r = img.getBoundingClientRect();
return { alt: img.alt, w: Math.round(r.width), h: Math.round(r.height), left: Math.round(r.left), top: Math.round(r.top + window.scrollY) };
})
Why:
For image optimizations or asset swaps, inspect actual loaded image URLs in the page and confirm the expected extension/path is being served.
Examples to verify in browser JS:
Array.from(document.images).map(img => ({
alt: img.alt,
src: img.currentSrc || img.src,
}))
Use filtering to confirm specific replacements, e.g. .webp assets.
npm run test:ci, npm run build)npm run dev -- --port <known-port>PORT=3456 npm run dev may still leave ambiguity in logs/workflow; prefer npm run dev -- --port 3456EADDRINUSE means the port is busy; it does not prove the right app is running there.next/dev/lock means another instance of the same repo is active; changing ports alone will not fix itWhen handing results back to the user, include: