{"record":{"id":"83f79113a2aeb621","repo":"denoland/deno","slug":"resolved-a-drive-letter-less-path-without-a-cwd","errorCode":null,"errorMessage":"Resolved a drive-letter-less path without a CWD.","messagePattern":"Resolved a drive-letter-less path without a CWD\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/path/_win32.ts","lineNumber":104,"sourceCode":"\n/**\n * Resolves path segments into a `path`\n * @param pathSegments to process to path\n */\nfunction resolve(...pathSegments: string[]): string {\n  let resolvedDevice = \"\";\n  let resolvedTail = \"\";\n  let resolvedAbsolute = false;\n\n  for (let i = pathSegments.length - 1; i >= -1; i--) {\n    let path: string;\n    // deno-lint-ignore no-explicit-any\n    const { Deno } = globalThis as any;\n    if (i >= 0) {\n      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","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/path/_win32.ts#L86-L122","documentation":"`path.win32.resolve()` falls back to the current working directory when the arguments do not produce a drive letter. That fallback needs a working `Deno.cwd`. When the runtime exposes no cwd function (the polyfill running outside a full Deno runtime), resolve throws this TypeError.","triggerScenarios":"`path.win32.resolve('a', 'b')` in an environment where `globalThis.Deno?.cwd` is absent — for example the polyfill bundled for a non-Deno target, or an embedder that strips Deno APIs. Any win32.resolve call whose arguments are all relative and drive-less.","commonSituations":"Cross-platform test suites that exercise win32 path logic on machines or runners without Deno APIs. Shipping Deno node:path polyfills through a bundler that tree-shakes or mocks the Deno global.","solutions":["Pass at least one absolute Windows path with a drive letter so no cwd fallback is needed.","Run the code under a full Deno runtime so `Deno.cwd` exists.","Use native `path.resolve` instead of `path.win32.resolve` when Windows semantics are not required."],"exampleFix":"// before\nconst p = path.win32.resolve('a', 'b'); // needs cwd fallback\n\n// after\nconst p = path.win32.resolve('C:\\\\base', 'a', 'b');","handlingStrategy":"validation","validationCode":"const canResolveRelative = () =>\n  typeof (globalThis as any)?.Deno?.cwd === 'function';\nif (!canResolveRelative() && !args.some((a) => /^[A-Za-z]:[\\\\/]/.test(String(a)))) {\n  throw new Error('win32.resolve needs an absolute drive path when no cwd API exists');\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('provide an absolute Windows path with a drive letter', { cause: err });\n  }\n  throw err;\n}","preventionTips":["Always seed win32.resolve with an absolute drive-anchored base path.","Do not bundle Deno's node:path polyfill for non-Deno targets; use the platform's own path module there.","In cross-platform code, prefer native path.resolve unless Windows semantics are required."],"tags":["path","win32","resolve","cwd","cross-platform","bundling"],"backgroundTag":"cwd-unavailable","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}