grafana/k6 · error
first argument expected to be a fs.File instance, got %T…
Error message
first argument expected to be a fs.File instance, got %T instead
What it means
Returned by csv.Parse when ExportTo cannot coerce the first Sobek argument into an fs.File — a type guard whose '%T' names the actual runtime type received. The API requires an opened file object (from k6/experimental/fs open()); passing a string path, a plain object, or any other value fires this immediately, before any parsing or option handling occurs.
Solutions
- Open the file first: const f = await open('data.csv') and pass the result to csv.parse
- Do not pass a file path string or raw object as the first argument
- Ensure you are not passing the result of a different module's open()
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at internal/js/modules/k6/experimental/csv/module.go:104 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18).
Data as JSON: /api/errors/bc539d526e1c645e.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/modules/k6/experimental/csv/module.go:104
// options holds the parser's as provided by the user.
options options
// vu is the VU instance that owns this module instance.
vu modules.VU
}
// parseSharedArrayNamePrefix is the prefix used for the shared array names created by the Parse function.
const parseSharedArrayNamePrefix = "csv.parse."
// Parse parses the provided CSV file, and returns a promise that resolves to a shared array
// containing the parsed data.
func (mi *ModuleInstance) Parse(file sobek.Value, options sobek.Value) (*sobek.Promise, error) {
rt := mi.vu.Runtime()
// 1. Make sure the Sobek object is a fs.File (Sobek operation)
var fileObj fs.File
if err := mi.vu.Runtime().ExportTo(file, &fileObj); err != nil {
return nil, fmt.Errorf("first argument expected to be a fs.File instance, got %T instead", file)
}
parserOptions := newDefaultParserOptions()
if options != nil {
var err error
parserOptions, err = newParserOptionsFrom(options.ToObject(rt))
if err != nil {
return nil, fmt.Errorf("failed to interpret the provided Parser options; reason: %w", err)
}
}
r, err := NewReaderFrom(fileObj.ReadSeekStater, parserOptions)
if err != nil {
return nil, fmt.Errorf("failed to create a new parser; reason: %w", err)
}
underlyingSharedArrayName, err := buildSharedArrayName(fileObj, parserOptions)
if err != nil {View on GitHub (pinned to 01ffac6f24)