{"id":"9cc032194d021b02","repo":"evanw/esbuild","slug":"invalid-packages","errorCode":null,"errorMessage":"Invalid packages","messagePattern":"Invalid packages","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_impl.go","lineNumber":226,"sourceCode":"func validateASCIIOnly(value Charset) bool {\n\tswitch value {\n\tcase CharsetDefault, CharsetASCII:\n\t\treturn true\n\tcase CharsetUTF8:\n\t\treturn false\n\tdefault:\n\t\tpanic(\"Invalid charset\")\n\t}\n}\n\nfunc validateExternalPackages(value Packages) bool {\n\tswitch value {\n\tcase PackagesDefault, PackagesBundle:\n\t\treturn false\n\tcase PackagesExternal:\n\t\treturn true\n\tdefault:\n\t\tpanic(\"Invalid packages\")\n\t}\n}\n\nfunc validateTreeShaking(value TreeShaking, bundle bool, format Format) bool {\n\tswitch value {\n\tcase TreeShakingDefault:\n\t\t// If we're in an IIFE then there's no way to concatenate additional code\n\t\t// to the end of our output so we assume tree shaking is safe. And when\n\t\t// bundling we assume that tree shaking is safe because if you want to add\n\t\t// code to the bundle, you should be doing that by including it in the\n\t\t// bundle instead of concatenating it afterward, so we also assume tree\n\t\t// shaking is safe then. Otherwise we assume tree shaking is not safe.\n\t\treturn bundle || format == FormatIIFE\n\tcase TreeShakingFalse:\n\t\treturn false\n\tcase TreeShakingTrue:\n\t\treturn true\n\tdefault:","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/pkg/api/api_impl.go#L208-L244","documentation":"A panic raised by validateExternalPackages when the Packages value is not PackagesDefault, PackagesBundle, or PackagesExternal. Internal invariant reachable only via Go-API misuse constructing an out-of-range Packages value.","triggerScenarios":"Go API: BuildOptions.Packages = Packages(5). The JS API's Packages option ('bundle' | 'external') maps to valid constants and cannot trigger this panic.","commonSituations":"Reflective config decoding; fork ordinal drift; unsafe casts.","solutions":["Use only PackagesDefault, PackagesBundle, or PackagesExternal.","Validate deserialized values against an allowlist.","Do not cast integers to Packages.","Pin a single esbuild version."],"exampleFix":"// before\nopts.Packages = api.Packages(5)\n\n// after\nopts.Packages = api.PackagesExternal","handlingStrategy":"type-guard","validationCode":"func validPackages(p api.Packages) bool {\n  switch p {\n  case api.PackagesDefault, api.PackagesBundle, api.PackagesExternal:\n    return true\n  }\n  return false\n}","typeGuard":"type Packages = 'bundle' | 'external'\nfunction isPackages(v: unknown): v is Packages {\n  return v === 'bundle' || v === 'external'\n}","tryCatchPattern":null,"preventionTips":["Use PackagesBundle or PackagesExternal only.","Validate deserialized config values.","Do not cast integers to Packages."],"tags":["api","packages","panic","invariant","go-api"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}