grafana/k6 · error
open() can't be used with directories, path
Error message
open() can't be used with directories, path: %q
What it means
Validation in readFile (initcontext.go): the path passed to open() resolves to a directory on the (fs) filesystem, not a readable file. k6 cannot return directory contents to the script.
Solutions
- Point open() at a file, not a directory
- Check for typos or missing filename in the path
- If loading multiple files, open each file individually
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at internal/js/initcontext.go:53 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/0bfb9f2b8b578803.
Report an issue: GitHub.
Appendix: source
Thrown at internal/js/initcontext.go:53
}
func readFile(fileSystem fsext.Fs, filename string) (data []byte, err error) {
defer func() {
if errors.Is(err, fsext.ErrPathNeverRequestedBefore) {
// loading different files per VU is not supported, so all files should are going
// to be used inside the scenario should be opened during the init step (without any conditions)
err = fmt.Errorf(
"open() can't be used with files that weren't previously opened during initialization (__VU==0), path: %q",
filename,
)
}
}()
// Workaround for https://github.com/spf13/fsext/issues/201
if isDir, err := fsext.IsDir(fileSystem, filename); err != nil {
return nil, err
} else if isDir {
return nil, fmt.Errorf("open() can't be used with directories, path: %q", filename)
}
return fsext.ReadFile(fileSystem, filename)
}
// allowOnlyOpenedFiles enables seen only files
func allowOnlyOpenedFiles(fs fsext.Fs) {
alreadyOpenedFS, ok := fs.(fsext.OnlyCachedEnabler)
if !ok {
return
}
alreadyOpenedFS.AllowOnlyCached()
}
func generateSourceMapLoader(logger logrus.FieldLogger, filesystems map[string]fsext.Fs,
) func(path string) ([]byte, error) {
return func(path string) ([]byte, error) {View on GitHub (pinned to 01ffac6f24)