grafana/k6 · critical
expected bundle type 'js', got '%s'
Error message
expected bundle type 'js', got '%s'
What it means
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.
Source
Thrown at internal/js/bundle.go:146
if err != nil {
return nil, err
}
bundle.ModuleResolver.Lock()
err = bundle.populateExports(updateOptions, bi)
if err != nil {
return nil, err
}
return bundle, nil
}
// NewBundleFromArchive creates a new bundle from an lib.Archive.
func NewBundleFromArchive(
piState *lib.TestPreInitState, arc *lib.Archive, mr *modules.ModuleResolver,
) (*Bundle, error) {
if arc.Type != "js" {
return nil, fmt.Errorf("expected bundle type 'js', got '%s'", arc.Type)
}
env := arc.Env
if env == nil {
// Older archives (<=0.20.0) don't have an "env" property
env = make(map[string]string)
}
maps.Copy(env, piState.RuntimeOptions.Env)
piState.RuntimeOptions.Env = env
return newBundle(piState, &loader.SourceData{
Data: arc.Data,
URL: arc.FilenameURL,
}, arc.Filesystems, arc.Options, false, mr)
}
func (b *Bundle) makeArchive() *lib.Archive {
clonedSourceDataURL, _ := url.Parse(b.sourceData.URL.String())View on GitHub (pinned to 93accf6570)
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
Example fix
# before: re-packed/hand-edited archive k6 run repacked.tar # ERRO ... expected bundle type 'js', got '' # after: build a clean archive from the source script k6 archive script.js && k6 run archive.tar
Defensive patterns
Strategy: validation
Validate before calling
# verify archive metadata before running if ! tar -xOf archive.tar metadata.json 2>/dev/null | grep -q '"type": *"js"'; then echo 'archive is not a k6 JavaScript archive - regenerate with: k6 archive script.js' >&2 exit 1 fi k6 run archive.tar
Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- Unexpected end of selector while parsing selector `${selecto
- missing required url
- browser process ended unexpectedly
- must be an object with key-value pairs
- urlTemplate must contain {key} placeholder
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/3ed34324f68f338e.
Report an issue: GitHub.