denoland/deno · error · TypeError

ERR_INVALID_ARG_VALUE

ERR_INVALID_ARG_VALUE

Error message

The argument 'filepath' Missing UNC resource path. Received ${filepath}

What it means

Thrown by url.pathToFileURL() in Deno's node:url polyfill when filepath looks like a Windows UNC path (starts with \\ or \\?\UNC\) but has no backslash after the server component, so the share/resource part is missing. Node's file URL scheme requires at least \\server\share, so conversion is refused. The check only runs under Windows path semantics (Windows host or options.windows === true).

Source

Thrown at ext/node/polyfills/url.ts:1639

    isWin && StringPrototypeStartsWith(filepath, "\\\\?\\") &&
    !StringPrototypeStartsWith(filepath, "\\\\?\\UNC\\")
  ) {
    const stripped = StringPrototypeSlice(filepath, 4);
    outURL.pathname = encodePathChars(stripped, { windows });
    return outURL;
  }
  if (isWin && StringPrototypeStartsWith(filepath, "\\\\")) {
    // UNC path format: \\server\share\resource
    // Extended UNC path format: \\?\UNC\server\share\resource
    const isExtendedUNC = StringPrototypeStartsWith(filepath, "\\\\?\\UNC\\");
    const prefixLength = isExtendedUNC ? 8 : 2;
    const hostnameEndIndex = StringPrototypeIndexOf(
      filepath,
      "\\",
      prefixLength,
    );
    if (hostnameEndIndex === -1) {
      throw new ERR_INVALID_ARG_VALUE(
        "filepath",
        filepath,
        "Missing UNC resource path",
      );
    }
    if (hostnameEndIndex === prefixLength) {
      throw new ERR_INVALID_ARG_VALUE(
        "filepath",
        filepath,
        "Empty UNC servername",
      );
    }
    const hostname = StringPrototypeSlice(
      filepath,
      prefixLength,
      hostnameEndIndex,
    );
    const rest = StringPrototypeSlice(filepath, hostnameEndIndex + 1);

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Include the share component: use at least '\\server\share' ('\\server\share\file.txt' for a file).
  2. Validate user/config-supplied UNC paths before conversion: after the \\ (or \\?\UNC\) prefix there must be a non-empty server followed by another backslash.
  3. For extended UNC keep the full form \\?\UNC\server\share\... — a backslash must follow the server name.
  4. If a UNC path was not intended, drop the leading \\ or pass a drive path like C:\data instead.

Example fix

// before — server only, no share
url.pathToFileURL("\\\\nas"); // throws ERR_INVALID_ARG_VALUE

// after — minimum valid UNC form
url.pathToFileURL("\\\\nas\\media"); // -> file://nas/media/
Defensive patterns

Strategy: validation

Validate before calling

function hasUncShare(p) {
  if (!p.startsWith("\\\\")) return true; // not a UNC path
  const prefix = p.startsWith("\\\\?\\UNC\\") ? 8 : 2;
  const i = p.indexOf("\\", prefix);
  return i > prefix; // \\server\share at minimum
}

Prevention

When it happens

Trigger: url.pathToFileURL('\\server') or url.pathToFileURL('\\?\UNC\server') on Windows or with { windows: true } — any input where indexOf('\\', prefixLength) is -1 (prefixLength 2 for \\, 8 for \\?\UNC\).

Common situations: Hand-typed or config-assembled SMB paths that omit the share name ('\\fileserver' instead of '\\fileserver\share'); path-building code that treats the share segment as optional; sanitizers that strip backslashes and eat the separator after the server; cross-platform tests forcing windows: true with truncated UNC fixtures.

Related errors


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