{"record":{"id":"53c5baae6f8dfce2","repo":"denoland/deno","slug":"resolved-a-relative-path-without-a-cwd","errorCode":null,"errorMessage":"Resolved a relative path without a CWD.","messagePattern":"Resolved a relative path without a CWD\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/path/_win32.ts","lineNumber":119,"sourceCode":"      path = pathSegments[i];\n    } else if (!resolvedDevice) {\n      if (typeof Deno?.cwd !== \"function\") {\n        throw new TypeError(\"Resolved a drive-letter-less path without a CWD.\");\n      }\n      path = Deno.cwd();\n      if (\n        pathSegments.length === 0 ||\n        ((pathSegments.length === 1 &&\n          (pathSegments[0] === \"\" || pathSegments[0] === \".\")) &&\n          isPathSeparator(StringPrototypeCharCodeAt(path, 0)))\n      ) {\n        return path;\n      }\n    } else {\n      if (\n        typeof Deno?.env?.get !== \"function\" || typeof Deno?.cwd !== \"function\"\n      ) {\n        throw new TypeError(\"Resolved a relative path without a CWD.\");\n      }\n      // Windows has the concept of drive-specific current working\n      // directories. If we've resolved a drive letter but not yet an\n      // absolute path, get cwd for that drive, or the process cwd if\n      // the drive cwd is not available. We're sure the device is not\n      // a UNC path at this points, because UNC paths are always absolute.\n      path = globalThis.process.env[`=${resolvedDevice}`] || Deno.cwd();\n\n      // Verify that a cwd was found and that it actually points\n      // to our drive. If not, default to the drive's root.\n      if (\n        path === undefined ||\n        (StringPrototypeToLowerCase(StringPrototypeSlice(path, 0, 2)) !==\n            StringPrototypeToLowerCase(resolvedDevice) &&\n          StringPrototypeCharCodeAt(path, 2) === CHAR_BACKWARD_SLASH)\n      ) {\n        path = `${resolvedDevice}\\\\`;\n      }","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/path/_win32.ts#L101-L137","documentation":"After `path.win32.resolve` finds a drive letter but no absolute target, it needs the drive-specific working directory: the `=C:` environment variable or `Deno.cwd`. When neither `Deno.env.get` nor `Deno.cwd` is a function, it throws this TypeError.","triggerScenarios":"`path.win32.resolve('C:', 'file.txt')` or `path.win32.resolve('C:file.txt')` — drive-relative inputs — in a runtime without the Deno global (bundled polyfill, non-Deno embedder, stripped sandbox).","commonSituations":"Same contexts as the drive-letter-less case: win32 path logic unit-tested outside Deno, polyfills bundled for other targets. Drive-relative Windows paths carried in config ('D:data') resolved on a machine without Windows.","solutions":["Use fully absolute targets: `path.win32.resolve('C:\\\\base', 'file.txt')`.","Expand drive-relative inputs against a known base before resolving.","Ensure the environment exposes env and cwd APIs — the check tests their presence as functions.","Prefer native `path.resolve` unless Windows drive semantics are required."],"exampleFix":"// before\nconst p = path.win32.resolve('C:', 'file.txt'); // drive-relative, needs cwd\n\n// after\nconst p = path.win32.resolve('C:\\\\base', 'file.txt');","handlingStrategy":"validation","validationCode":"const hasRuntimeEnv = () =>\n  typeof (globalThis as any)?.Deno?.env?.get === 'function' &&\n  typeof (globalThis as any)?.Deno?.cwd === 'function';\nconst isAbsoluteWin = (p) => /^[A-Za-z]:[\\\\/]/.test(p);\nif (!hasRuntimeEnv() && args.some((a) => /^[A-Za-z]:[^\\\\/]/.test(String(a)))) {\n  throw new Error('drive-relative input needs env/cwd; pass an absolute base');\n}\nreturn path.win32.resolve(...args);","typeGuard":null,"tryCatchPattern":"try {\n  p = path.win32.resolve(...args);\n} catch (err) {\n  if (err instanceof TypeError && /without a CWD/.test(err.message)) {\n    throw new Error('expand drive-relative paths against an absolute base', { cause: err });\n  }\n  throw err;\n}","preventionTips":["Expand drive-relative inputs ('C:file') against a known base before resolving.","Keep env/cwd APIs available in the runtime that runs win32 path logic.","Unit-test win32.resolve cases in the same runtime you ship, not a stripped harness."],"tags":["path","win32","resolve","cwd","drive-relative","cross-platform"],"backgroundTag":"cwd-unavailable","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}