{"record":{"id":"3ed34324f68f338e","repo":"grafana/k6","slug":"expected-bundle-type-js-got-s","errorCode":null,"errorMessage":"expected bundle type 'js', got '%s'","messagePattern":"expected bundle type 'js', got '(.+?)'","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/js/bundle.go","lineNumber":146,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\tbundle.ModuleResolver.Lock()\n\n\terr = bundle.populateExports(updateOptions, bi)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn bundle, nil\n}\n\n// NewBundleFromArchive creates a new bundle from an lib.Archive.\nfunc NewBundleFromArchive(\n\tpiState *lib.TestPreInitState, arc *lib.Archive, mr *modules.ModuleResolver,\n) (*Bundle, error) {\n\tif arc.Type != \"js\" {\n\t\treturn nil, fmt.Errorf(\"expected bundle type 'js', got '%s'\", arc.Type)\n\t}\n\n\tenv := arc.Env\n\tif env == nil {\n\t\t// Older archives (<=0.20.0) don't have an \"env\" property\n\t\tenv = make(map[string]string)\n\t}\n\tmaps.Copy(env, piState.RuntimeOptions.Env)\n\tpiState.RuntimeOptions.Env = env\n\n\treturn newBundle(piState, &loader.SourceData{\n\t\tData: arc.Data,\n\t\tURL:  arc.FilenameURL,\n\t}, arc.Filesystems, arc.Options, false, mr)\n}\n\nfunc (b *Bundle) makeArchive() *lib.Archive {\n\tclonedSourceDataURL, _ := url.Parse(b.sourceData.URL.String())","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/bundle.go#L128-L164","documentation":"NewBundleFromArchive loads a tar produced by `k6 archive`; the archive's metadata.json carries a `type` field that must be 'js' (core k6 only ever writes that value). This guard in internal/js/bundle.go:146 rejects anything else before attempting to parse the script - foreign tars, corrupted metadata, or archives stamped with a different type by external tooling/xk6 extensions.","triggerScenarios":"`k6 run some.tar` where metadata.json is missing, corrupt, or has type != \"js\"; Go code calling js.NewBundleFromArchive with an lib.Archive built by another tool; a tar that was unpacked, edited, and re-packed without a valid metadata.json.","commonSituations":"Pipelines that transform or re-package archives (adding files, renaming) and drop or mangle metadata.json; passing an unrelated .tar to k6 run; archives produced by third-party tooling that emits its own type field.","solutions":["Regenerate the archive from source: `k6 archive script.js` then `k6 run archive.tar`","Inspect the tar metadata: `tar -xOf archive.tar metadata.json` and confirm it contains \"type\": \"js\"","If archiving is not needed, run the .js script directly"],"exampleFix":"# before: re-packed/hand-edited archive\nk6 run repacked.tar  # ERRO ... expected bundle type 'js', got ''\n\n# after: build a clean archive from the source script\nk6 archive script.js && k6 run archive.tar","handlingStrategy":"validation","validationCode":"# verify archive metadata before running\nif ! tar -xOf archive.tar metadata.json 2>/dev/null | grep -q '\"type\": *\"js\"'; then\n  echo 'archive is not a k6 JavaScript archive - regenerate with: k6 archive script.js' >&2\n  exit 1\nfi\nk6 run archive.tar","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate archives with k6 archive from source instead of hand-editing tar contents","Keep metadata.json untouched when repacking archives (only add data files)","Run a smoke `k6 inspect archive.tar` in CI to catch broken archives before load runs"],"tags":["archive","tar","metadata","startup"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}