{"record":{"id":"a99464dc26a33e7d","repo":"denoland/deno","slug":"uvwasi-enoent","errorCode":"UVWASI_ENOENT","errorMessage":"uvwasi_init: failed to open preopen \"${realPathString}\"","messagePattern":"uvwasi_init: failed to open preopen \"(.+?)\"","errorType":"exception","errorClass":"UVWASIError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/wasi.ts","lineNumber":195,"sourceCode":"      const value = entry[1];\n      ArrayPrototypePush(envPairs, [key, String(value)]);\n    }\n\n    if (options.preopens !== undefined) {\n      validateObject(options.preopens, \"options.preopens\");\n    }\n    const preopens: [string, string][] = [];\n    if (options.preopens) {\n      for (\n        const entry of new SafeArrayIterator(ObjectEntries(options.preopens))\n      ) {\n        const virtualPath = entry[0];\n        const realPath = entry[1];\n        const realPathString = String(realPath);\n        try {\n          statSync(realPathString);\n        } catch {\n          throw new UVWASIError(\n            \"UVWASI_ENOENT\",\n            `uvwasi_init: failed to open preopen \"${realPathString}\"`,\n          );\n        }\n        ArrayPrototypePush(preopens, [String(virtualPath), realPathString]);\n      }\n    }\n\n    if (options.returnOnExit !== undefined) {\n      validateBoolean(options.returnOnExit, \"options.returnOnExit\");\n    }\n\n    if (options.stdin !== undefined) {\n      validateInt32(options.stdin, \"options.stdin\");\n    }\n    if (options.stdout !== undefined) {\n      validateInt32(options.stdout, \"options.stdout\");\n    }","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/wasi.ts#L177-L213","documentation":"Thrown during WASI construction when one of the entries in options.preopens points to a host path that does not exist. Before registering a preopen, the polyfill runs statSync on the mapped real path; if the stat fails for any reason (usually ENOENT, but also EACCES on a parent directory), it raises a UVWASIError with code UVWASI_ENOENT, matching libuvwasi's 'uvwasi_init: failed to open preopen' message.","triggerScenarios":"`new WASI({ version: 'preview1', preopens: { '/data': './does-not-exist' } })`; preopens built from process.argv or env vars that are unset, so the path becomes 'undefined'; relative paths resolved against an unexpected cwd (worker thread, bundled binary, test runner); a path with a typo or wrong case on case-sensitive filesystems.","commonSituations":"Running a script from a different working directory than assumed (npm lifecycle scripts, systemd services, Docker WORKDIR changes); sandbox directories that the deploy step was supposed to create but did not; CI checkout paths differing from local ones.","solutions":["Verify the mapped directory exists before constructing WASI (see validationCode) and create it with mkdirSync(dir, { recursive: true }) if missing.","Use absolute paths: `preopens: { '/data': path.resolve('./data') }` so resolution does not depend on cwd.","Double-check spelling and case of every path in the preopens map against the filesystem."],"exampleFix":"// before\nconst wasi = new WASI({ version: 'preview1', preopens: { '/data': './data' } });\n\n// after\nimport { mkdirSync } from 'node:fs';\nimport path from 'node:path';\nconst dataDir = path.resolve('./data');\nmkdirSync(dataDir, { recursive: true });\nconst wasi = new WASI({ version: 'preview1', preopens: { '/data': dataDir } });","handlingStrategy":"validation","validationCode":"import { statSync, mkdirSync } from 'node:fs';\nimport path from 'node:path';\n\nconst preopens: Record<string, string> = {};\nfor (const [virtual, raw] of Object.entries(userPreopens)) {\n  const real = path.resolve(String(raw));\n  statSync(real); // rethrows a clear ENOENT if missing\n  // or: mkdirSync(real, { recursive: true });\n  preopens[virtual] = real;\n}\nconst wasi = new WASI({ version: 'preview1', preopens });","typeGuard":null,"tryCatchPattern":"try {\n  return new WASI({ version: 'preview1', preopens });\n} catch (err) {\n  if ((err as { code?: string }).code === 'UVWASI_ENOENT') {\n    throw new Error('WASI preopen directory missing — check preopens map paths');\n  }\n  throw err;\n}","preventionTips":["Resolve every preopen path to an absolute path with path.resolve before passing it in.","Create sandbox directories eagerly with mkdirSync(dir, { recursive: true }).","Never build preopen paths by concatenating possibly-undefined env vars or argv entries."],"tags":["wasi","preopens","filesystem","path-not-found","node-compat"],"backgroundTag":"file-not-found","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}