{"record":{"id":"fa6f892d7cefbc30","repo":"stablyai/orca","slug":"packaged-main-file-file-was-not-found-in-asar","errorCode":null,"errorMessage":"Packaged main file ${file} was not found in ${asarPath}","messagePattern":"Packaged main file (.+?) was not found in (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"config/packaged-runtime-node-modules.cjs","lineNumber":228,"sourceCode":"\nfunction findAsarEntry(entries, expectedPath) {\n  return entries.find((entry) => normalizeAsarEntryPath(entry) === expectedPath)\n}\n\nfunction verifyPackagedMainRuntimeDeps(resourcesDir, asar = require('@electron/asar')) {\n  const asarPath = join(resourcesDir, 'app.asar')\n  if (!existsSync(asarPath)) {\n    return\n  }\n\n  const mainFiles = ['out/main/index.js', 'out/main/agent-hooks/managed-agent-hook-controls.js']\n  const entries = asar.listPackage(asarPath)\n  const missing = new Set()\n\n  for (const file of mainFiles) {\n    const entry = findAsarEntry(entries, file)\n    if (!entry) {\n      throw new Error(`Packaged main file ${file} was not found in ${asarPath}`)\n    }\n\n    // Why: @electron/asar lists entries with host separators; Windows returns\n    // backslashes, and extractFile expects that same host-style path.\n    const internalPath = entry.replace(/^[\\\\/]+/, '')\n    const source = asar.extractFile(asarPath, internalPath).toString('utf8')\n    for (const match of source.matchAll(/require\\([\"']([^\"']+)[\"']\\)/g)) {\n      const specifier = match[1]\n      if (!isPackagedExternalSpecifier(specifier)) {\n        continue\n      }\n      const packageName = packageNameFromSpecifier(specifier)\n      if (!existsSync(join(resourcesDir, 'node_modules', ...packageName.split('/')))) {\n        missing.add(packageName)\n      }\n    }\n  }\n","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/packaged-runtime-node-modules.cjs#L210-L246","documentation":"The `verifyPackagedMainRuntimeDeps` function opens the packaged app.asar archive and looks for specific main bundle files ('out/main/index.js' and 'out/main/agent-hooks/managed-agent-hook-controls.js'). If either is not found in the asar entry list, this error fires. This is a layout contract check — it verifies the asar contains the expected entry points before scanning them for bare require() calls.","triggerScenarios":"The main bundle entry was renamed in the rollup config (electron.vite.config.ts input keys) without updating the `mainFiles` list at line 221. The build produced output to a different directory structure (e.g., 'out/main/' became 'out/electron-main/'). The asar packaging excluded these files via the `files` filter in electron-builder config. A build step that moves or renames output files after rollup but before asar packing.","commonSituations":"Renaming the rollup input key for index.js or managed-agent-hook-controls. Changing the output directory structure in the vite/rollup config. The `files` exclusion patterns in electron-builder.config.cjs accidentally filtering out these paths. A vite plugin that changes output file naming.","solutions":["Check the `mainFiles` array at packaged-runtime-node-modules.cjs:221 — if you renamed the rollup input for the main entry or agent-hooks entry, update the paths here.","Inspect the actual asar contents: `npx @electron/asar list path/to/app.asar | grep 'out/main/'` to see what paths are actually present.","Check the `files` filter in electron-builder.config.cjs — ensure none of the exclusion patterns accidentally match the main bundle output.","Verify the rollup output config (`entryFileNames: '[name].js'`) hasn't changed to add a hash or prefix."],"exampleFix":"// before — rollup input renamed from 'index' to 'main-index'\n// electron.vite.config.ts\ninput: { 'main-index': resolve('src/main/index.ts') }\n\n// after — update mainFiles in packaged-runtime-node-modules.cjs\nconst mainFiles = ['out/main/main-index.js', 'out/main/agent-hooks/managed-agent-hook-controls.js']","handlingStrategy":"validation","validationCode":"// Verify expected main files exist in the asar before scanning\nimport asar from '@electron/asar'\nfunction verifyMainFilesInAsar(asarPath, expectedFiles) {\n  const entries = asar.listPackage(asarPath)\n  const missing = expectedFiles.filter(f =>\n    !entries.some(e => e.replace(/\\\\/g, '/').replace(/^\\/+/, '') === f)\n  )\n  if (missing.length) throw new Error(`Missing in asar: ${missing.join(', ')}`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When renaming a rollup input key for the main entry or agent-hooks, update the mainFiles list at packaged-runtime-node-modules.cjs:221.","Run `npx @electron/asar list app.asar` to inspect packaged contents after build changes.","Keep the output config `entryFileNames: '[name].js'` stable — hashing or prefixes will break the path check."],"tags":["packaging","asar","build-layout","rollup","verification"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}