{"record":{"id":"edafada400bfbf4b","repo":"evanw/esbuild","slug":"invalid-format","errorCode":null,"errorMessage":"Invalid format","messagePattern":"Invalid format","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"pkg/api/api_impl.go","lineNumber":132,"sourceCode":"\tcase PlatformNeutral:\n\t\treturn config.PlatformNeutral\n\tdefault:\n\t\tpanic(\"Invalid platform\")\n\t}\n}\n\nfunc validateFormat(value Format) config.Format {\n\tswitch value {\n\tcase FormatDefault:\n\t\treturn config.FormatPreserve\n\tcase FormatIIFE:\n\t\treturn config.FormatIIFE\n\tcase FormatCommonJS:\n\t\treturn config.FormatCommonJS\n\tcase FormatESModule:\n\t\treturn config.FormatESModule\n\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}","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/evanw/esbuild/blob/f6058f8364fe7ab91ca57a83e02577ed74c9cae4/pkg/api/api_impl.go#L114-L150","documentation":"validateFormat (pkg/api/api_impl.go:132) panics when Format is not one of FormatDefault(0), FormatIIFE(1), FormatCommonJS(2), FormatESModule(3). Format dictates the output module wrapper; an unknown value means esbuild cannot pick a code generator, so it aborts rather than emit ambiguous output. The panic is reached from validateBuildOptions when constructing OutputFormat.","triggerScenarios":"Passing BuildOptions.Format (or TransformOptions.Format) assigned from an integer literal, a deserialized payload, or a stale constant that no longer exists. The panic occurs in the option-validation pass of api.Build/api.Transform/api.Context, before scanning entry points.","commonSituations":"Bridging the JS API to the Go core with a mismatched version (e.g. js_table.ts regenerated ordinals after a re-vendor), JSON-decoding config where Format is stored as a number, or copying `Format: api.FormatPreserve` (a constant that does not exist in the public API) from outdated docs.","solutions":["Use only the documented constants: api.FormatDefault / FormatIIFE / FormatCommonJS / FormatESModule; FormatDefault lets esbuild choose based on Platform and Bundle.","Sanitize any externally-supplied integer against {0,1,2,3} before casting to Format.","Lock esbuild to a single version across your stack (go.mod + package.json) and regenerate any bridge code after upgrades.","Replace numeric `Format` fields in serialized config files with named strings mapped at load time."],"exampleFix":"// before\nopts := api.BuildOptions{Format: api.Format(9), Bundle: true}\n\n// after\nopts := api.BuildOptions{Format: api.FormatESModule, Bundle: true}","handlingStrategy":"validation","validationCode":"func checkFormat(f api.Format) error {\n    switch f {\n    case api.FormatDefault, api.FormatIIFE, api.FormatCommonJS, api.FormatESModule:\n        return nil\n    }\n    return fmt.Errorf(\"invalid format %d (want 0..3)\", uint8(f))\n}\n\n// before build:\nif err := checkFormat(opts.Format); err != nil { return err }","typeGuard":"func isValidFormat(f api.Format) bool {\n    switch f {\n    case api.FormatDefault, api.FormatIIFE, api.FormatCommonJS, api.FormatESModule:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Use FormatDefault and let esbuild pick (IIFE for browser bundle, CJS for node bundle, ESM for neutral).","Persist Format as a string (\"iife\"/\"cjs\"/\"esm\") and translate to the constant at load.","Add a CI check that fails if the vendored esbuild version differs across go.mod and any wrapper.","Write a config round-trip test exercising every enum field."],"tags":["esbuild","config","validation","panic","format","enum"],"backgroundTag":null,"analyzedSha":"f6058f8364fe7ab91ca57a83e02577ed74c9cae4","analyzedAt":"2026-08-09T18:37:22.223Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}