{"record":{"id":"682f488075d6ce2a","repo":"grafana/k6","slug":"open-failed-reason-unable-to-access-the-file-s","errorCode":null,"errorMessage":"open() failed; reason: unable to access the file system","messagePattern":"open\\(\\) failed; reason: unable to access the file system","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/experimental/fs/module.go","lineNumber":121,"sourceCode":"\nfunc (mi *ModuleInstance) openImpl(path string) (*File, error) {\n\tinitEnv := mi.vu.InitEnv()\n\t// Strip file scheme if available as we should support only this scheme\n\tpath = strings.TrimPrefix(path, \"file://\")\n\n\t// We resolve the path relative to the entrypoint script, as opposed to\n\t// the current working directory (the k6 command is called from).\n\t//\n\t// This is done on purpose, although it diverges in some respect with\n\t// how files are handled in different k6 contexts, so that we cater to\n\t// and intuitive user experience.\n\t//\n\t// See #2781 and #2674.\n\tpath = fsext.Abs(initEnv.CWD.Path, path)\n\n\tfs, ok := initEnv.FileSystems[\"file\"]\n\tif !ok {\n\t\treturn nil, errors.New(\"open() failed; reason: unable to access the file system\")\n\t}\n\n\tif exists, err := fsext.Exists(fs, path); err != nil {\n\t\treturn nil, fmt.Errorf(\"open() failed, unable to verify if %q exists; reason: %w\", path, err)\n\t} else if !exists {\n\t\treturn nil, newFsError(NotFoundError, fmt.Sprintf(\"no such file or directory %q\", path))\n\t}\n\n\tif isDir, err := fsext.IsDir(fs, path); err != nil {\n\t\treturn nil, fmt.Errorf(\"open() failed, unable to verify if %q is a directory; reason: %w\", path, err)\n\t} else if isDir {\n\t\treturn nil, newFsError(\n\t\t\tInvalidResourceError,\n\t\t\tfmt.Sprintf(\"cannot open %q: opening a directory is not supported\", path),\n\t\t)\n\t}\n\n\tdata, err := mi.cache.open(path, fs)","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/experimental/fs/module.go#L103-L139","documentation":"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().","triggerScenarios":"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.","commonSituations":"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).","solutions":["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).","If you execute archives (k6 archive / k6 run archive.tar), rebuild the archive after adding the file so it is bundled.","If this is a custom binary/extension, register a file system under the 'file' key of the init environment before the init context runs.","Verify you are not hitting a stripped environment (cloud execution) - move the data inline or into a supported source."],"exampleFix":"// before: environment provides no 'file' file system\nimport fs from 'k6/experimental/fs';\nexport default async function () {\n  const f = await fs.open('./data.txt'); // rejects: unable to access the file system\n}\n\n// after: run locally with the file present next to the entrypoint script\n// k6 run script.js  (data.txt in the same directory)","handlingStrategy":"try-catch","validationCode":"// fs.open returns a promise - guard with .catch\nimport fs from 'k6/experimental/fs';\nlet file;\ntry { file = await fs.open('./data.txt'); } catch (e) { /* handle */ }","typeGuard":null,"tryCatchPattern":"try {\n  const f = await fs.open('./data.bin');\n} catch (e) {\n  if (/unable to access the file system/.test(e.message)) {\n    console.error('No file system in this execution environment; bundle the file or run locally');\n  }\n  throw e;\n}","preventionTips":["Verify data files ship with the script/archive before running in restricted environments.","Test scripts locally with k6 run before cloud/remote execution.","Treat 'unable to access the file system' as an environment problem, not a path problem - a bad path yields a NotFoundError instead."],"tags":["k6","fs","file-system","open","experimental"],"backgroundTag":"file-system-unavailable","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}