{"record":{"id":"65cd442765235bdf","repo":"evanw/esbuild","slug":"invalid-source-map","errorCode":null,"errorMessage":"Invalid source map","messagePattern":"Invalid source map","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_impl.go","lineNumber":149,"sourceCode":"\tdefault:\n\t\tpanic(\"Invalid format\")\n\t}\n}\n\nfunc validateSourceMap(value SourceMap) config.SourceMap {\n\tswitch value {\n\tcase SourceMapNone:\n\t\treturn config.SourceMapNone\n\tcase SourceMapLinked:\n\t\treturn config.SourceMapLinkedWithComment\n\tcase SourceMapInline:\n\t\treturn config.SourceMapInline\n\tcase SourceMapExternal:\n\t\treturn config.SourceMapExternalWithoutComment\n\tcase SourceMapInlineAndExternal:\n\t\treturn config.SourceMapInlineAndExternal\n\tdefault:\n\t\tpanic(\"Invalid source map\")\n\t}\n}\n\nfunc validateLegalComments(value LegalComments, bundle bool) config.LegalComments {\n\tswitch value {\n\tcase LegalCommentsDefault:\n\t\tif bundle {\n\t\t\treturn config.LegalCommentsEndOfFile\n\t\t} else {\n\t\t\treturn config.LegalCommentsInline\n\t\t}\n\tcase LegalCommentsNone:\n\t\treturn config.LegalCommentsNone\n\tcase LegalCommentsInline:\n\t\treturn config.LegalCommentsInline\n\tcase LegalCommentsEndOfFile:\n\t\treturn config.LegalCommentsEndOfFile\n\tcase LegalCommentsLinked:","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_impl.go#L131-L167","documentation":"validateSourceMap (pkg/api/api_impl.go:149) panics when BuildOptions.Sourcemap is not SourceMapNone(0), SourceMapInline(1), SourceMapLinked(2), SourceMapExternal(3), or SourceMapInlineAndExternal(4). The function returns the internal config.SourceMap mode used by the linker; an unknown enum means esbuild cannot decide how (or whether) to emit .map data, so it aborts. Reached via validateBuildOptions at options construction.","triggerScenarios":"Assigning Sourcemap from an out-of-range integer or a deserialized struct where the field is `uint8`. Common when config is shipped over a wire format (JSON, msgpack) and later cast to SourceMap without bounds checking.","commonSituations":"Persisted build configs that predate a renamed enum, version drift between a wrapper (e.g. Vite/webpack-loader internals) and the vendored esbuild, or a typo such as `Sourcemap: api.SourceMapBoth` (no such constant).","solutions":["Set Sourcemap using api.SourceMapNone / SourceMapInline / SourceMapLinked / SourceMapExternal / SourceMapInlineAndExternal only.","If loading config from JSON, map a string key (e.g. \"linked\") to the constant instead of decoding a raw number.","Bounds-check any int-to-SourceMap cast against 0..4.","Realign wrapper and core esbuild versions; re-vendor go.mod to a single commit."],"exampleFix":"// before\nopts := api.BuildOptions{Sourcemap: api.SourceMap(8)}\n\n// after\nopts := api.BuildOptions{Sourcemap: api.SourceMapLinked}","handlingStrategy":"validation","validationCode":"func checkSourceMap(s api.SourceMap) error {\n    switch s {\n    case api.SourceMapNone, api.SourceMapInline, api.SourceMapLinked,\n        api.SourceMapExternal, api.SourceMapInlineAndExternal:\n        return nil\n    }\n    return fmt.Errorf(\"invalid source map %d (want 0..4)\", uint8(s))\n}","typeGuard":"func isValidSourceMap(s api.SourceMap) bool {\n    switch s {\n    case api.SourceMapNone, api.SourceMapInline, api.SourceMapLinked,\n        api.SourceMapExternal, api.SourceMapInlineAndExternal:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Default to SourceMapNone unless you actually need maps.","Avoid decoding JSON numbers directly into SourceMap; map from strings.","Keep wrapper and core esbuild versions aligned.","Add a regression test that fails if any SourceMap constant is removed/renamed upstream."],"tags":["esbuild","config","validation","panic","sourcemap","enum"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}