{"record":{"id":"12cf7cc8d3fb0ba8","repo":"remix-run/remix","slug":"invalid-browser-hmr-channel-port-port","errorCode":null,"errorMessage":"Invalid browser HMR channel port: ${port}","messagePattern":"Invalid browser HMR channel port: (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/node-hmr/src/index.ts","lineNumber":242,"sourceCode":"  if (options === false) return null\n  if (options === undefined || options === true) return {}\n\n  if (options.port !== undefined) {\n    assertValidPort(options.port)\n  }\n\n  return options\n}\n\nfunction resolveRegisterPath(): string {\n  let extension = import.meta.url.endsWith('.ts') ? 'ts' : 'js'\n\n  return fileURLToPath(new URL(`./register.${extension}`, import.meta.url))\n}\n\nfunction assertValidPort(port: number): void {\n  if (!Number.isInteger(port) || port < 0 || port > 65_535) {\n    throw new TypeError(`Invalid browser HMR channel port: ${port}`)\n  }\n}\n","sourceCodeStart":224,"sourceCodeEnd":245,"githubUrl":"https://github.com/remix-run/remix/blob/9696913134be3a4423513d2775f7b31d6917c049/packages/node-hmr/src/index.ts#L224-L245","documentation":"assertValidPort throws a TypeError when the browser HMR channel port is not an integer between 0 and 65535. It validates options passed to normalizeBrowserHmrChannelOptions in node-hmr before they are used to open the event stream, catching garbage config early.","triggerScenarios":"Passing a fractional, negative, NaN, or >65535 port (e.g. from a string env var parsed incorrectly or a placeholder value) as the browser HMR channel port in node-hmr runtime options.","commonSituations":"Reading a port from an environment variable without Number() conversion or with parseFloat producing decimals; defaulting to -1 or 99999 as a sentinel; config typos.","solutions":["Coerce env strings with Number() and validate with Number.isInteger before passing","Use a real port in 0-65535, or 0 to let the OS assign one","Remove placeholder/sentinel values from config"],"exampleFix":"// before\ncreateNodeHmrRuntime({ browserHmrChannel: { port: Number(process.env.HMR_PORT ?? '3000.5') } })\n\n// after\nlet port = Number(process.env.HMR_PORT ?? 3000)\nif (!Number.isInteger(port) || port < 0 || port > 65535) throw new Error('Bad HMR_PORT')\ncreateNodeHmrRuntime({ browserHmrChannel: { port } })","handlingStrategy":"validation","validationCode":"function isValidPort(port: number): boolean {\n  return Number.isInteger(port) && port >= 0 && port <= 65535\n}\n\nlet port = Number(config.hmrPort)\nif (!isValidPort(port)) throw new Error(`Invalid HMR port: ${config.hmrPort}`)","typeGuard":"function isValidPort(port: unknown): port is number {\n  return typeof port === 'number' && Number.isInteger(port) && port >= 0 && port <= 65535\n}","tryCatchPattern":"try {\n  normalizeBrowserHmrChannelOptions(opts)\n} catch (error) {\n  if (error instanceof TypeError && /browser HMR channel port/.test(error.message)) {\n    // fix config and continue with a default port\n  } else throw error\n}","preventionTips":["Convert port env vars with Number() and validate with Number.isInteger","Never use sentinel values like -1 or 99999 for 'unset' — use undefined"],"tags":["node-hmr","port","validation","config"],"backgroundTag":"invalid-port-config","analyzedSha":"9696913134be3a4423513d2775f7b31d6917c049","analyzedAt":"2026-08-27T19:55:01.024Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}