{"id":"c7304a3391daf108","repo":"evanw/esbuild","slug":"invalid-target","errorCode":null,"errorMessage":"Invalid target","messagePattern":"Invalid target","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_impl.go","lineNumber":335,"sourceCode":"\tcase ES2018:\n\t\tconstraints[compat.ES] = compat.Semver{Parts: []int{2018}}\n\tcase ES2019:\n\t\tconstraints[compat.ES] = compat.Semver{Parts: []int{2019}}\n\tcase ES2020:\n\t\tconstraints[compat.ES] = compat.Semver{Parts: []int{2020}}\n\tcase ES2021:\n\t\tconstraints[compat.ES] = compat.Semver{Parts: []int{2021}}\n\tcase ES2022:\n\t\tconstraints[compat.ES] = compat.Semver{Parts: []int{2022}}\n\tcase ES2023:\n\t\tconstraints[compat.ES] = compat.Semver{Parts: []int{2023}}\n\tcase ES2024:\n\t\tconstraints[compat.ES] = compat.Semver{Parts: []int{2024}}\n\tcase ES2025:\n\t\tconstraints[compat.ES] = compat.Semver{Parts: []int{2025}}\n\tcase ESNext, DefaultTarget:\n\tdefault:\n\t\tpanic(\"Invalid target\")\n\t}\n\n\tfor _, engine := range engines {\n\t\tif match := versionRegex.FindStringSubmatch(engine.Version); match != nil {\n\t\t\tif major, err := strconv.Atoi(match[1]); err == nil {\n\t\t\t\tparts := []int{major}\n\t\t\t\tif minor, err := strconv.Atoi(match[2]); err == nil {\n\t\t\t\t\tparts = append(parts, minor)\n\t\t\t\t\tif patch, err := strconv.Atoi(match[3]); err == nil {\n\t\t\t\t\t\tparts = append(parts, patch)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tconstraints[convertEngineName(engine.Name)] = compat.Semver{\n\t\t\t\t\tParts:      parts,\n\t\t\t\t\tPreRelease: match[4],\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}","sourceCodeStart":317,"sourceCodeEnd":353,"githubUrl":"https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/pkg/api/api_impl.go#L317-L353","documentation":"A panic raised by validateFeatures when the Target value is not one of the documented ECMA targets (ES5, ES2015..ES2025, ESNext, DefaultTarget). Reachable only through Go-API misuse that constructs an out-of-range Target; the JS API's Target union ('es5' | 'es2015' | ... | 'esnext') maps to valid constants and cannot trigger it.","triggerScenarios":"Go API: BuildOptions.Target = Target(123). The JS API cannot reach this panic. Fires inside validateFeatures during the target/engine compatibility computation.","commonSituations":"Reflective config decoding; fork ordinal drift; unsafe casts; passing a numeric target from a roadmap string like 'es2030' that esbuild does not yet know.","solutions":["Use only the documented Target constants (ES5, ES2015..ES2025, ESNext, DefaultTarget).","For a future/unknown target, fall back to ESNext rather than casting a number.","Validate deserialized target values against an allowlist.","Pin a single esbuild version and re-check target support after upgrades."],"exampleFix":"// before\nopts.Target = api.Target(123)\n\n// after\nopts.Target = api.ES2022  // or ESNext for bleeding-edge","handlingStrategy":"type-guard","validationCode":"func validTarget(t api.Target) bool {\n  switch t {\n  case api.DefaultTarget, api.ES5, api.ES2015, api.ES2016, api.ES2017, api.ES2018, api.ES2019, api.ES2020, api.ES2021, api.ES2022, api.ES2023, api.ES2024, api.ES2025, api.ESNext:\n    return true\n  }\n  return false\n}","typeGuard":"type Target = 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'es2023' | 'es2024' | 'es2025' | 'esnext'\nconst TARGETS = new Set<Target>(['es5','es2015','es2016','es2017','es2018','es2019','es2020','es2021','es2022','es2023','es2024','es2025','esnext'])\nfunction isTarget(v: unknown): v is Target {\n  return typeof v === 'string' && (TARGETS as Set<string>).has(v)\n}","tryCatchPattern":null,"preventionTips":["Use only documented Target constants.","For bleeding-edge output use ESNext, never a guessed ordinal.","Re-check supported targets after each esbuild upgrade."],"tags":["api","target","panic","invariant","go-api"],"analyzedSha":"6ff1d8b0d8c134e867a397eef39702a223ebef9e","analyzedAt":"2026-08-03T19:42:38.433Z","schemaVersion":2}