{"record":{"id":"a5210b2f3c3d122f","repo":"github/copilot-sdk","slug":"could-not-find-copilotcliversion-in-package-json-o","errorCode":null,"errorMessage":"could not find copilotCliVersion in package.json or @github/copilot in package-lock.json","messagePattern":"could not find copilotCliVersion in package\\.json or @github/copilot in package-lock\\.json","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/cmd/bundler/main.go","lineNumber":371,"sourceCode":"\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to fetch legacy package-lock.json: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"failed to fetch legacy package-lock.json: %s\", resp.Status)\n\t}\n\n\tvar packageLock struct {\n\t\tPackages map[string]struct {\n\t\t\tVersion string `json:\"version\"`\n\t\t} `json:\"packages\"`\n\t}\n\tif err := json.NewDecoder(resp.Body).Decode(&packageLock); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to parse legacy package-lock.json: %w\", err)\n\t}\n\tpkg, ok := packageLock.Packages[\"node_modules/@github/copilot\"]\n\tif !ok || pkg.Version == \"\" {\n\t\treturn \"\", fmt.Errorf(\"could not find copilotCliVersion in package.json or @github/copilot in package-lock.json\")\n\t}\n\treturn pkg.Version, nil\n}\n\n// isHex returns true if s contains only hexadecimal characters.\nfunc isHex(s string) bool {\n\tfor _, c := range s {\n\t\tif (c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F') {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}\n\ntype bundleArtifacts struct {\n\tbinaryPath          string\n\tbinaryHash          []byte\n\truntimeArtifactPath string","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/cmd/bundler/main.go#L353-L389","documentation":"The legacy package-lock.json downloaded and parsed successfully, but the expected key node_modules/@github/copilot is missing or has an empty version field. The bundler throws this because it cannot determine the CLI version from either package.json (copilotCliVersion) or the legacy lockfile fallback.","triggerScenarios":"packageLock.Packages lacks the key \"node_modules/@github/copilot\", or that entry's Version is empty string, after a successful fetch+parse in fetchLegacyCLIVersionFromRepo — usually because copilotCliVersion was also absent from package.json (otherwise the fallback would not run).","commonSituations":"The repository renamed/moved the @github/copilot dependency or switched to a different package name; a very old or very new lockfile layout (e.g. npm v1 lockfile without a packages map); gitRef pointing at a commit before the dependency was added.","solutions":["Inspect the lockfile at that ref: does packages[\"node_modules/@github/copilot\"] exist and have a version?","Point gitRef at a commit/tag where the dependency exists under that path.","Update the lookup key if the package was renamed or moved.","Pin copilotCliVersion in package.json so the legacy fallback is not required.","Handle npm v1 lockfile format (dependencies tree) if old refs must be supported."],"exampleFix":"// before\npkg, ok := packageLock.Packages[\"node_modules/@github/copilot\"]\nif !ok || pkg.Version == \"\" {\n\treturn \"\", fmt.Errorf(\"could not find copilotCliVersion in package.json or @github/copilot in package-lock.json\")\n}\n// after\npkg, ok := packageLock.Packages[\"node_modules/@github/copilot\"]\nif !ok || pkg.Version == \"\" {\n\treturn \"\", fmt.Errorf(\"@github/copilot not found in package-lock.json at ref %s (packages has %d entries)\", gitRef, len(packageLock.Packages))\n}","handlingStrategy":"validation","validationCode":"// preflight: confirm the key exists in the lockfile at the ref\nout, _ := exec.Command(\"git\", \"show\", ref+\":package-lock.json\").Output()\nvar lock struct{ Packages map[string]struct{ Version string } }\njson.Unmarshal(out, &lock)\nif _, ok := lock.Packages[\"node_modules/@github/copilot\"]; !ok {\n\treturn errors.New(\"@github/copilot absent from lockfile at \" + ref)\n}","typeGuard":null,"tryCatchPattern":"v, err := fetchCLIVersionFromRepo(ref)\nif err != nil && strings.Contains(err.Error(), \"could not find copilotCliVersion\") {\n\t// pick a gitRef where the dependency exists, or set copilotCliVersion explicitly\n}","preventionTips":["Pin copilotCliVersion in package.json as the primary source.","Confirm the package path node_modules/@github/copilot before changing refs.","Use refs newer than the commit that added the dependency.","Support both npm v1 and v2+ lockfile layouts if old refs matter."],"tags":["lookup","missing-key","package-lock","fallback"],"backgroundTag":"resource-not-found","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}