grafana/k6 · error

open() failed; reason: unable to access the file system

Error message

open() failed; reason: unable to access the file system

What it means

The experimental fs module's open() resolves paths against the script and then looks up initEnv.FileSystems['file'], the file system k6 mounts for the init context (populated by the runner from the local disk or the archive). If that registry has no 'file' entry, no local file access exists at all in this execution, and openImpl returns this error which rejects the promise returned by open().

Solutions

  1. Run the script with the standard runner and the data file present next to the script: k6 run script.js (paths resolve relative to the script).
  2. If you execute archives (k6 archive / k6 run archive.tar), rebuild the archive after adding the file so it is bundled.
  3. If this is a custom binary/extension, register a file system under the 'file' key of the init environment before the init context runs.
  4. Verify you are not hitting a stripped environment (cloud execution) - move the data inline or into a supported source.

Example fix

// before: environment provides no 'file' file system
import fs from 'k6/experimental/fs';
export default async function () {
  const f = await fs.open('./data.txt'); // rejects: unable to access the file system
}

// after: run locally with the file present next to the entrypoint script
// k6 run script.js  (data.txt in the same directory)
Defensive patterns

Strategy: try-catch

Validate before calling

// fs.open returns a promise - guard with .catch
import fs from 'k6/experimental/fs';
let file;
try { file = await fs.open('./data.txt'); } catch (e) { /* handle */ }

Try / catch

try {
  const f = await fs.open('./data.bin');
} catch (e) {
  if (/unable to access the file system/.test(e.message)) {
    console.error('No file system in this execution environment; bundle the file or run locally');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling open() from 'k6/experimental/fs' in an execution environment that provides no file system: custom embedded runners/harnesses that don't register one, some remote/cloud execution modes where local files are not mounted, or module unit tests instantiating the module without an init file system. Note this is different from a missing file, which produces a NotFoundError.

Common situations: Running scripts through custom k6 builds or extensions where the file system provider is not wired in; executing in CI containers or cloud runners where the working archive contains no local file mounts; calling fs.open() in contexts the runner never intended (e.g. handleSummary).

Related errors


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/682f488075d6ce2a. Report an issue: GitHub.

Appendix: source

Thrown at internal/js/modules/k6/experimental/fs/module.go:121

func (mi *ModuleInstance) openImpl(path string) (*File, error) {
	initEnv := mi.vu.InitEnv()
	// Strip file scheme if available as we should support only this scheme
	path = strings.TrimPrefix(path, "file://")

	// We resolve the path relative to the entrypoint script, as opposed to
	// the current working directory (the k6 command is called from).
	//
	// This is done on purpose, although it diverges in some respect with
	// how files are handled in different k6 contexts, so that we cater to
	// and intuitive user experience.
	//
	// See #2781 and #2674.
	path = fsext.Abs(initEnv.CWD.Path, path)

	fs, ok := initEnv.FileSystems["file"]
	if !ok {
		return nil, errors.New("open() failed; reason: unable to access the file system")
	}

	if exists, err := fsext.Exists(fs, path); err != nil {
		return nil, fmt.Errorf("open() failed, unable to verify if %q exists; reason: %w", path, err)
	} else if !exists {
		return nil, newFsError(NotFoundError, fmt.Sprintf("no such file or directory %q", path))
	}

	if isDir, err := fsext.IsDir(fs, path); err != nil {
		return nil, fmt.Errorf("open() failed, unable to verify if %q is a directory; reason: %w", path, err)
	} else if isDir {
		return nil, newFsError(
			InvalidResourceError,
			fmt.Sprintf("cannot open %q: opening a directory is not supported", path),
		)
	}

	data, err := mi.cache.open(path, fs)

View on GitHub (pinned to 01ffac6f24)