{"record":{"id":"1370fc8204a760d4","repo":"stablyai/orca","slug":"packaged-main-bundle-has-bare-runtime-imports-with","errorCode":null,"errorMessage":"Packaged main bundle has bare runtime imports without copied node_modules: ${[...missing].join(', ')}","messagePattern":"Packaged main bundle has bare runtime imports without copied node_modules: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"config/packaged-runtime-node-modules.cjs","lineNumber":248,"sourceCode":"\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\n  if (missing.size > 0) {\n    throw new Error(\n      `Packaged main bundle has bare runtime imports without copied node_modules: ${[\n        ...missing\n      ].join(', ')}`\n    )\n  }\n}\n\nfunction normalizeNodePtyWindowsArch(electronArch) {\n  const architecture = normalizeElectronArchitecture(electronArch)\n  if (architecture !== 'x64' && architecture !== 'arm64') {\n    throw new Error(`Unsupported packaged node-pty Windows architecture: ${architecture}`)\n  }\n  return architecture\n}\n\nfunction normalizeElectronArchitecture(electronArch) {\n  const architecture =\n    typeof electronArch === 'number'","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/stablyai/orca/blob/1136503c6a231a16dce8f921f6fadb63d181e8db/config/packaged-runtime-node-modules.cjs#L230-L266","documentation":"The `verifyPackagedMainRuntimeDeps` function scans the source of the packaged main bundle files for `require(\"...\")` calls with bare specifiers (non-relative, non-electron, non-builtin). For each, it checks if the package exists at `resources/node_modules/packageName`. If any are missing, this error lists them. This catches the case where a new runtime dependency was added to the main bundle but wasn't included in the packaged node_modules copy.","triggerScenarios":"Adding a `require('new-package')` to the main bundle source (src/main/index.ts or agent-hooks) without adding 'new-package' to PACKAGED_RUNTIME_PACKAGE_ROOTS in packaged-runtime-node-modules.cjs. A dependency that was previously bundled (in BUNDLED_MAIN_DEPENDENCIES) being moved to external, making it a bare require that needs packaged node_modules.","commonSituations":"Importing a new npm package in main process code without updating the packaging config. Changing the externalizeDeps configuration so a previously-bundled dependency becomes external. Adding a require() for a scoped package (@scope/name) — the packageNameFromSpecifier function handles this, but the package must still be in the roots.","solutions":["Read the error — it lists the exact missing package names. For each, add it to PACKAGED_RUNTIME_PACKAGE_ROOTS in packaged-runtime-node-modules.cjs:16.","If the package should be bundled instead of external (no runtime require), add it to BUNDLED_MAIN_DEPENDENCIES in electron.vite.config.ts so Rollup inlines it.","Verify the package is installed: `ls node_modules/missing-package-name`.","For scoped packages, ensure the full scope/name is in the roots list."],"exampleFix":"// before — main bundle requires a new package\nconst { parse } = require('new-parser')\n\n// after — add to PACKAGED_RUNTIME_PACKAGE_ROOTS\nconst PACKAGED_RUNTIME_PACKAGE_ROOTS = [\n  // ...existing...\n  'new-parser'\n]","handlingStrategy":"validation","validationCode":"// Scan main bundle source for bare requires and check node_modules coverage\nimport { readFileSync, existsSync, readdirSync } from 'fs'\nimport { join } from 'path'\nfunction verifyRuntimeDepsCovered(mainBundlePath, resourcesDir) {\n  const source = readFileSync(mainBundlePath, 'utf8')\n  const requires = [...source.matchAll(/require\\([\"']([^\"']+)[\"']\\)/g)].map(m => m[1])\n  const bare = requires.filter(s => !s.startsWith('.') && s !== 'electron')\n  const missing = bare.filter(s => {\n    const pkg = s.startsWith('@') ? s.split('/').slice(0, 2).join('/') : s.split('/')[0]\n    return !existsSync(join(resourcesDir, 'node_modules', pkg))\n  })\n  if (missing.length) throw new Error(`Missing node_modules for: ${missing.join(', ')}`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When adding a require() for a new package in main process code, add it to PACKAGED_RUNTIME_PACKAGE_ROOTS immediately.","Keep BUNDLED_MAIN_DEPENDENCIES and PACKAGED_RUNTIME_PACKAGE_ROOTS in sync — moving a dep from bundled to external requires updating both.","Run the full packaging step locally after import changes to catch this before CI."],"tags":["packaging","runtime-deps","node-modules","asar","verification","rollup"],"backgroundTag":null,"analyzedSha":"1136503c6a231a16dce8f921f6fadb63d181e8db","analyzedAt":"2026-08-12T23:15:58.167Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}