{"record":{"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":350,"sourceCode":"\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 ES2026:\n\t\tconstraints[compat.ES] = compat.Semver{Parts: []int{2026}}\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\tname := convertEngineName(engine.Name)\n\t\t\t\tnew := 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\tif old, ok := constraints[name]; ok && compat.CompareSemver(old, new) < 0 {","sourceCodeStart":332,"sourceCodeEnd":368,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_impl.go#L332-L368","documentation":"validateFeatures (pkg/api/api_impl.go:350) panics when BuildOptions.Target is not DefaultTarget(0) nor one of ESNext/ES5/ES2015..ES2026. The target is translated into a compat.Semver constraint used to disable unsupported JS/CSS features; an unknown target cannot be mapped to a feature set, so esbuild aborts. Reached from validateBuildOptions via validateFeatures before engines are processed.","triggerScenarios":"Passing Target as a raw integer outside the declared enum, deserializing it from a numeric config, or referencing a constant that does not exist in this esbuild version (e.g. ES2027 against an older binary). The panic fires during options validation, before any file is scanned.","commonSituations":"Running against an older esbuild than your config targets (new ES20xx constants are added over time), version drift between the JS API and the Go core after re-vendoring, or a typo such as `Target: api.ES2020Stable`.","solutions":["Use DefaultTarget (let esbuild choose) or one of the declared ES* constants that your esbuild version supports; ESNext avoids feature-gating entirely.","If loading target from a string, map \"es2022\" etc. to constants at load and reject unknown strings with a clear error.","Bounds-check decoded integers against 0..14 (the enum length at this version) before casting.","Upgrade esbuild (and rebuild bridges) to a version that supports the target you need."],"exampleFix":"// before\nopts := api.BuildOptions{Target: api.Target(20)}\n\n// after\nopts := api.BuildOptions{Target: api.DefaultTarget}","handlingStrategy":"validation","validationCode":"func checkTarget(t api.Target) error {\n    switch t {\n    case api.DefaultTarget, api.ESNext, api.ES5,\n        api.ES2015, api.ES2016, api.ES2017, api.ES2018, api.ES2019,\n        api.ES2020, api.ES2021, api.ES2022, api.ES2023, api.ES2024,\n        api.ES2025, api.ES2026:\n        return nil\n    }\n    return fmt.Errorf(\"invalid target %d\", uint8(t))\n}","typeGuard":"func isValidTarget(t api.Target) bool {\n    switch t {\n    case api.DefaultTarget, api.ESNext, api.ES5,\n        api.ES2015, api.ES2016, api.ES2017, api.ES2018, api.ES2019,\n        api.ES2020, api.ES2021, api.ES2022, api.ES2023, api.ES2024,\n        api.ES2025, api.ES2026:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Use DefaultTarget unless you need to gate features; ESNext disables feature-gating entirely.","When parsing a target string from user config, reject unknown values explicitly instead of guessing an ordinal.","After an esbuild upgrade that adds a new ES20xx constant, regenerate any bridge and widen your validation.","Bounds-check integers to the current enum length before casting."],"tags":["esbuild","config","validation","panic","target","enum"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}