Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/next/src/server/lib/router-utils/setup-dev-bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import { isParallelRouteSegment } from '../../../shared/lib/segment'
import { ensureLeadingSlash } from '../../../shared/lib/page-path/ensure-leading-slash'
import { Lockfile } from '../../../build/lockfile'
import { deobfuscateText } from '../../../shared/lib/magic-identifier'
import { spawnSync } from 'child_process'

export type SetupOpts = {
renderServer: LazyRenderServerInstance
Expand Down Expand Up @@ -362,6 +363,16 @@ async function startWatcher(
)
},
})
const originalConsoleError = console.error
console.error = (...args: any[]) => {
const msg = args[0]
if (typeof msg === 'string' && msg.includes('EMFILE')) {
spawnSync(`lsof`, [`-a`, `-p`, `${process.pid}`], {
stdio: 'inherit',
})
}
originalConsoleError(...args)
}
const fileWatchTimes = new Map()
let enabledTypeScript = await verifyTypeScript(opts)
let previousClientRouterFilters: any
Expand Down
16 changes: 13 additions & 3 deletions packages/next/src/server/lib/start-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import path from 'path'
import http from 'http'
import https from 'https'
import os from 'os'
import { exec } from 'child_process'
import { exec, spawnSync } from 'child_process'
import Watchpack from 'next/dist/compiled/watchpack'
import * as Log from '../../build/output/log'
import setupDebug from 'next/dist/compiled/debug'
Expand Down Expand Up @@ -512,6 +512,16 @@ export async function startServer(
onChange: (filename: string) => void
) {
const wp = new Watchpack()
const originalConsoleError = console.error
console.error = (...args: any[]) => {
const msg = args[0]
if (typeof msg === 'string' && msg.includes('EMFILE')) {
spawnSync(`lsof`, [`-a`, `-p`, `${process.pid}`], {
stdio: 'inherit',
})
}
originalConsoleError(...args)
}
wp.watch({
files: CONFIG_FILES.map((file) => path.join(dirToWatch, file)),
})
Expand All @@ -526,9 +536,9 @@ export async function startServer(
}

Log.warn(
`Found a change in ${path.basename(
`Found a change in ${
filename
)}. Restarting the server to apply the changes...`
}. Restarting the server to apply the changes...`
Comment on lines +539 to +541
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`Found a change in ${
filename
)}. Restarting the server to apply the changes...`
}. Restarting the server to apply the changes...`
`Found a change in ${path.basename(
filename
)}. Restarting the server to apply the changes...`

The log message now displays the full file path instead of just the filename, making the output unnecessarily verbose and harder to scan.

View Details

Analysis

Log message in watchConfigFiles displays full file path instead of just filename

What fails: The watchConfigFiles callback in packages/next/src/server/lib/start-server.ts (lines 539-541) displays the complete file path in the warning message instead of just the config filename, reducing dev server log readability.

How to reproduce:

  1. Run next dev in a Next.js project
  2. Modify a config file (e.g., next.config.js, middleware.ts, etc.)
  3. Observe the warning message in the console

Result: Log displays:

Found a change in /Users/dev/project/next.config.js. Restarting the server to apply the changes...

Expected: Should display only the filename per the original code pattern:

Found a change in next.config.js. Restarting the server to apply the changes...

Root cause: The path.basename() call was removed from the log message, but Watchpack's 'change' event callback receives the full file path (constructed via path.join(dirToWatch, file) on line 526). This was verified by testing Watchpack's behavior - it returns the complete path string, not just the filename.

Fix: Restore the path.basename() call to extract just the filename from the full path provided by Watchpack's change event.

)
process.exit(RESTART_EXIT_CODE)
})
Expand Down
Loading