{"record":{"id":"cd26a8901d1f7ff7","repo":"vercel/next.js","slug":"hmrrefresh-can-only-be-used-in-development-mode-p","errorCode":null,"errorMessage":"hmrRefresh can only be used in development mode. Please use refresh instead.","messagePattern":"hmrRefresh can only be used in development mode\\. Please use refresh instead\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/client/components/app-router-instance.ts","lineNumber":486,"sourceCode":"        options?.scroll === false\n          ? ScrollBehavior.NoScroll\n          : ScrollBehavior.Default,\n        null,\n        options?.transitionTypes,\n        null\n      )\n    })\n  },\n  refresh: () => {\n    startTransition(() => {\n      dispatchAppRouterAction({\n        type: ACTION_REFRESH,\n      })\n    })\n  },\n  hmrRefresh: () => {\n    if (process.env.NODE_ENV !== 'development') {\n      throw new Error(\n        'hmrRefresh can only be used in development mode. Please use refresh instead.'\n      )\n    } else {\n      // Reset the known routes table so that route predictions are cleared\n      // when routes change during development.\n      resetKnownRoutes()\n      let signal: AbortSignal | undefined\n      if (process.env.__NEXT_SERVER_COMPONENTS_HMR_CANCELLATION) {\n        // Abort the superseded generation before scheduling the new one, so its\n        // request is torn down as early as possible. Halting (not rejecting)\n        // makes the abort safe regardless of order.\n        activeHmrRefreshController?.abort()\n        activeHmrRefreshController = new AbortController()\n        signal = activeHmrRefreshController.signal\n      }\n      startTransition(() => {\n        dispatchAppRouterAction({\n          type: ACTION_HMR_REFRESH,","sourceCodeStart":468,"sourceCodeEnd":504,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/client/components/app-router-instance.ts#L468-L504","documentation":"`router.hmrRefresh()` is a development-only method that triggers Hot Module Replacement for the current route. It throws unconditionally when `process.env.NODE_ENV !== 'development'` because HMR infrastructure does not exist in production builds. The error message directs you to use `router.refresh()` instead, which works in all environments.","triggerScenarios":"Calling `router.hmrRefresh()` in code that executes during a production build (`next build`) or production server (`next start`).","commonSituations":"Dev-only debugging code left in a production code path; a custom dev toolbar or plugin that calls hmrRefresh without environment checks; shared utility code used in both dev and prod.","solutions":["Use `router.refresh()` instead — it works in all environments.","Guard the call: `if (process.env.NODE_ENV === 'development') router.hmrRefresh()`.","Remove the hmrRefresh call from code paths that run in production."],"exampleFix":"// before — throws in production\nrouter.hmrRefresh()\n\n// after — use refresh (works everywhere)\nrouter.refresh()\n// or guard the dev-only method:\nif (process.env.NODE_ENV === 'development') {\n  router.hmrRefresh()\n}","handlingStrategy":"validation","validationCode":"function safeHmrRefresh(router: { hmrRefresh: () => void; refresh: () => void }): void {\n  if (process.env.NODE_ENV === 'development') {\n    router.hmrRefresh()\n  } else {\n    router.refresh()\n  }\n}","typeGuard":"function isDev(): boolean {\n  return process.env.NODE_ENV === 'development'\n}","tryCatchPattern":null,"preventionTips":["Prefer router.refresh() which works in all environments.","Guard hmrRefresh() calls with a NODE_ENV check.","Remove dev-only router calls from code paths shipped to production."],"tags":["router","hmr","development","production","environment"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}