{"record":{"id":"7cb2bb0de71aee0e","repo":"github/copilot-sdk","slug":"could-not-resolve-packagename-for-copilot-cli","errorCode":null,"errorMessage":"Could not resolve ${packageName} for Copilot CLI ${version}.","messagePattern":"Could not resolve (.+?) for Copilot CLI (.+?)\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nodejs/src/runtimeArtifacts.ts","lineNumber":262,"sourceCode":"    packageName: string,\n    searchPaths = require.resolve.paths(packageName) ?? []\n): string | undefined {\n    return searchPaths\n        .map((base) => join(base, ...packageName.split(\"/\")))\n        .find((candidate) => existsSync(join(candidate, \"package.json\")));\n}\n\nexport async function ensureRuntimeBundle(\n    version: string,\n    options: EnsureRuntimeBundleOptions = {}\n): Promise<string> {\n    const platform = options.platform ?? getRuntimePlatform();\n    // lgtm[js/trivial-conditional] This generated constant is true for internal canary builds.\n    if (COPILOT_CLI_USE_NPM_PACKAGE) {\n        const packageName = `@github/copilot-${platform}`;\n        const packageRoot = resolvePackageRoot(packageName, options.packageSearchPaths);\n        if (!packageRoot) {\n            throw new Error(`Could not resolve ${packageName} for Copilot CLI ${version}.`);\n        }\n        validateFile(\n            join(packageRoot, \"prebuilds\", platform, \"runtime.node\"),\n            \"Copilot runtime.node\"\n        );\n        return materializeRuntimeBundle(\n            { packageRoot, platform },\n            options.cacheRoot,\n            `${version}-${platform}`\n        );\n    }\n\n    const packageName = getRuntimePackageName(platform);\n    const packageRoot = resolvePackageRoot(packageName, options.packageSearchPaths);\n    if (!packageRoot) {\n        throw new Error(\n            `Could not resolve ${packageName}. Reinstall @github/copilot-sdk so its platform package is installed.`\n        );","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/nodejs/src/runtimeArtifacts.ts#L244-L280","documentation":"In the npm-package resolution path (COPILOT_CLI_USE_NPM_PACKAGE builds), ensureRuntimeBundle locates the per-platform package @github/copilot-<platform> via resolvePackageRoot. When it cannot be found it throws, naming the package and CLI version, because the bundled runtime.node is the only way to run Copilot CLI in this mode.","triggerScenarios":"ensureRuntimeBundle (via getBundledRuntimePath/runtimePath) runs with the npm-package flag enabled and no entry for @github/copilot-<platform> in packageSearchPaths/node_modules.","commonSituations":"Internal canary builds installed without their platform package, pnpm/yarn PnP layouts not covered by search paths, trimmed production installs (--omit=optional), monorepo hoisting moving the package elsewhere.","solutions":["Install/restore the platform package matching getRuntimePlatform() output.","Reinstall with optional dependencies enabled: npm install (avoid --omit=optional).","Pass options.packageSearchPaths pointing at the node_modules roots that actually contain the package.","For pnpm/PnP setups, add the platform package as a direct dependency so the linker keeps it."],"exampleFix":"// before\nnpm install @github/copilot-sdk --omit=optional\n\n// after\nnpm install @github/copilot-sdk @github/copilot-linux-x64","handlingStrategy":"validation","validationCode":"import { resolvePackageRoot } from './runtimeArtifacts';\nif (!resolvePackageRoot('@github/copilot-linux-x64', searchPaths)) throw new Error('platform package not installed');","typeGuard":null,"tryCatchPattern":"try {\n  const path = getBundledRuntimePath();\n} catch (e) {\n  if (e.message.startsWith('Could not resolve @github/copilot-')) {\n    // install the named platform package or fix packageSearchPaths\n  } else throw e;\n}","preventionTips":["Add the platform package as a direct dependency in monorepos/pnpm setups.","Never install with --omit=optional.","Sanity-check resolution of the platform package in a startup health check."],"tags":["npm","package-resolution","missing-dependency","nodejs"],"backgroundTag":"missing-optional-dependency","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}