{"record":{"id":"0249ea9e235fd6df","repo":"decolua/9router","slug":"mitm-server-js-not-found-at-effectiveserverpath","errorCode":null,"errorMessage":"MITM server.js not found at ${effectiveServerPath}. Reinstall 9router.","messagePattern":"MITM server\\.js not found at (.+?)\\. Reinstall 9router\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"src/mitm/manager.js","lineNumber":581,"sourceCode":"      try {\n        await installCert(password, rootCACertPath);\n        log(\"🔐 Cert: ✅ trusted\");\n      } catch (e) {\n        throw new Error(`Failed to trust certificate: ${e.message}`);\n      }\n    }\n  } else {\n    log(\"🔐 Cert: already trusted ✅\");\n  }\n\n  // Step 2: Spawn server (Root CA already installed in Step 1.5)\n  // Verify server.js exists — recopy if runtime file was deleted (antivirus/cleanup)\n  let effectiveServerPath = SERVER_PATH;\n  if (!effectiveServerPath || !fs.existsSync(effectiveServerPath)) {\n    log(`[MITM] server.js missing at ${effectiveServerPath} → recopying`);\n    effectiveServerPath = ensureRuntimeServer(resolveBundledServerPath());\n    if (!effectiveServerPath || !fs.existsSync(effectiveServerPath)) {\n      throw new Error(`MITM server.js not found at ${effectiveServerPath}. Reinstall 9router.`);\n    }\n  }\n  const mitmRouterBase = await resolveMitmRouterBaseUrl();\n  log(`🚀 Starting server... (router: ${mitmRouterBase})`);\n  if (IS_WIN) {\n    // Check port 443 — ask user before killing\n    const winOwner = await getPort443Owner(sudoPassword);\n    if (winOwner) {\n      if (forceKillPort443) {\n        log(`Killing process on port 443 (PID ${winOwner.pid}, name=${winOwner.name})...`);\n        await killPort443Owner(winOwner, sudoPassword);\n      } else {\n        const e = new Error(`Port 443 is already in use by \"${winOwner.name}\" (PID ${winOwner.pid}).`);\n        e.code = \"PORT_443_BUSY\";\n        e.portOwner = { pid: winOwner.pid, name: winOwner.name };\n        throw e;\n      }\n    }","sourceCodeStart":563,"sourceCodeEnd":599,"githubUrl":"https://github.com/decolua/9router/blob/90b52e06ffd666b7929554211474d01588f6b1f8/src/mitm/manager.js#L563-L599","documentation":"Before spawning the MITM worker, startServer verifies SERVER_PATH (the runtime-copied mitm server.js) exists. If missing, it re-copies the bundled copy via ensureRuntimeServer(resolveBundledServerPath()) and re-checks; if the recopy also yields nothing it throws 'MITM server.js not found at <path>. Reinstall 9router.' This means the runtime asset could not be located or restored from the installed package.","triggerScenarios":"SERVER_PATH unset or the runtime file deleted (antivirus quarantine, disk cleanup) AND resolveBundledServerPath() returns null/empty or a non-existent path — e.g. running from a source checkout without the bundled asset, a broken/partial npm install, or a package layout change where the bundled server.js isn't where expected.","commonSituations":"Windows Defender or corporate AV quarantining mitm server.js repeatedly (this is exactly the recopy path's reason for existing); installing via a truncated npm cache or partial download; running cli/ from a dev clone where the bundling step that places the asset wasn't run; upgrading versions with a stale half-deleted runtime directory under ~/.9router.","solutions":["Reinstall the package: `npm install -g 9router` (or re-run the CLI installer) so the bundled server asset is restored","Check whether AV quarantined the file and whitelist ~/.9router (and the package install dir) before reinstalling","Verify the runtime dir contents — delete the MITM runtime folder under ~/.9router so the next start recopies everything fresh from the bundle","If developing locally, run the build/bundle step that emits the MITM server asset and confirm resolveBundledServerPath() points at an existing file"],"exampleFix":"// after reinstalling, force a clean recopy\nrm -rf ~/.9router/mitm && npx 9router start\n// or in code, verify before starting\nif (!fs.existsSync(serverPath)) await reinstall9router(); // before startServer(apiKey)","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nconst path = require('path');\nfunction assertMitmRuntimePresent() {\n  const mitmDir = require('os').homedir() + '/.9router/mitm';\n  const serverPath = path.join(mitmDir, 'server.js');\n  if (!fs.existsSync(serverPath)) {\n    throw new Error(`MITM runtime missing at ${serverPath} — reinstall 9router before starting the proxy.`);\n  }\n  return serverPath;\n}","typeGuard":null,"tryCatchPattern":"try {\n  await startServer(apiKey);\n} catch (e) {\n  if (/MITM server\\.js not found/.test(e.message)) {\n    console.error('Runtime files missing — reinstalling 9router is required:', e.message);\n    // do NOT retry; surface an actionable reinstall step to the user\n  } else throw e;\n}","preventionTips":["Whitelist ~/.9router and the global npm install dir in antivirus/EDR software","After any version upgrade, verify the runtime server.js exists before starting","Reinstall via npm rather than copying files by hand so bundled assets land correctly","In CI/Docker, bake the runtime copy into the image instead of relying on first-start recopy"],"tags":["filesystem","missing-file","installation","antivirus","mitm"],"backgroundTag":"missing-runtime-file","analyzedSha":"90b52e06ffd666b7929554211474d01588f6b1f8","analyzedAt":"2026-08-30T21:05:45.952Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}