denoland/deno · error · TypeError

Resolved a drive-letter-less path without a CWD.

Error message

Resolved a drive-letter-less path without a CWD.

What it means

`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.

Source

Thrown at ext/node/polyfills/path/_win32.ts:104

/**
 * Resolves path segments into a `path`
 * @param pathSegments to process to path
 */
function resolve(...pathSegments: string[]): string {
  let resolvedDevice = "";
  let resolvedTail = "";
  let resolvedAbsolute = false;

  for (let i = pathSegments.length - 1; i >= -1; i--) {
    let path: string;
    // deno-lint-ignore no-explicit-any
    const { Deno } = globalThis as any;
    if (i >= 0) {
      path = pathSegments[i];
    } else if (!resolvedDevice) {
      if (typeof Deno?.cwd !== "function") {
        throw new TypeError("Resolved a drive-letter-less path without a CWD.");
      }
      path = Deno.cwd();
      if (
        pathSegments.length === 0 ||
        ((pathSegments.length === 1 &&
          (pathSegments[0] === "" || pathSegments[0] === ".")) &&
          isPathSeparator(StringPrototypeCharCodeAt(path, 0)))
      ) {
        return path;
      }
    } else {
      if (
        typeof Deno?.env?.get !== "function" || typeof Deno?.cwd !== "function"
      ) {
        throw new TypeError("Resolved a relative path without a CWD.");
      }
      // Windows has the concept of drive-specific current working
      // directories. If we've resolved a drive letter but not yet an

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Pass at least one absolute Windows path with a drive letter so no cwd fallback is needed.
  2. Run the code under a full Deno runtime so `Deno.cwd` exists.
  3. Use native `path.resolve` instead of `path.win32.resolve` when Windows semantics are not required.

Example fix

// before
const p = path.win32.resolve('a', 'b'); // needs cwd fallback

// after
const p = path.win32.resolve('C:\\base', 'a', 'b');
Defensive patterns

Strategy: validation

Validate before calling

const canResolveRelative = () =>
  typeof (globalThis as any)?.Deno?.cwd === 'function';
if (!canResolveRelative() && !args.some((a) => /^[A-Za-z]:[\\/]/.test(String(a)))) {
  throw new Error('win32.resolve needs an absolute drive path when no cwd API exists');
}
return path.win32.resolve(...args);

Try / catch

try {
  p = path.win32.resolve(...args);
} catch (err) {
  if (err instanceof TypeError && /without a CWD/.test(err.message)) {
    throw new Error('provide an absolute Windows path with a drive letter', { cause: err });
  }
  throw err;
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/83f79113a2aeb621. Report an issue: GitHub.