Next.js dev server HMR and fast-refresh fail for symlinked package in pnpm workspace (stale pages in browser)
Environment
Monorepo managed by pnpm 7 workspaces, Next.js 13.4 app (app directory) on macOS 13, shared UI components located in packages/ui symlinked into app via pnpm; development server run with next dev, using Vite-based tooling for some packages.
Symptoms
When editing React components inside packages/ui, Next dev prints 'compiled successfully' but the browser page remains unchanged (stale UI). Full page refresh sometimes shows updated code, but fast-refresh/HMR does not apply component updates reliably. Console shows no HMR errors.
Observations
Filesystem watcher warnings appear in the terminal intermittently: chokidar or watchpack logs indicate 'watch not available' for the symlinked path. next dev resolves imports to /path/to/.pnpm/.../node_modules/@workspace/ui (symlink target) rather than the package source. Adding console.log to components in package triggers rebuild but HMR not injected to the app bundle. Setting NODE_OPTIONS=--preserve-symlinks changes module resolution but breaks other imports.
Already attempted
Restarted dev server repeatedly; tried next dev with --experimental-watcher polling; set NODE_OPTIONS=--preserve-symlinks; used next-transpile-modules and added ui package to transpilePackages in next.config.js; added watchFolders pointing to the package source path; cleared .next cache; none provided a consistent fix—some changes pick up, others don't.
Question
How can I get reliable fast-refresh/HMR in Next.js dev when using pnpm symlinked workspace packages so edits in the shared package update the running app without manual full-refresh?
Verified community troubleshooting
No answers yet..