denoland/deno · error · TypeError

Request mode 'navigate' is not allowed

Error message

Request mode 'navigate' is not allowed

What it means

The fetch spec only allows RequestInit.mode values "same-origin", "cors", "no-cors", and "navigate" — but "navigate" is reserved for browser navigation and explicitly rejected in the Request constructor step 19. Passing init.mode === "navigate" throws TypeError "Request mode 'navigate' is not allowed".

Solutions

  1. Remove mode: "navigate" — omit mode entirely (defaults to "cors")
  2. Use "same-origin", "cors", or "no-cors" as appropriate
  3. Drop "navigate" from any user-selectable mode list in your config

Example fix

// before
new Request("https://example.com/page", { mode: "navigate" }); // throws

// after
new Request("https://example.com/page", { mode: "no-cors" }); // pick a real mode
// or simply omit it:
new Request("https://example.com/page");
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED_MODES = new Set(["same-origin", "cors", "no-cors"]);
const mode = ALLOWED_MODES.has(init.mode) ? init.mode : undefined;
const req = new Request(url, { ...init, mode });

Type guard

const ALLOWED_MODES = new Set(["same-origin", "cors", "no-cors"]);
function isAllowedRequestMode(m: unknown): boolean {
  return m === undefined || (typeof m === "string" && ALLOWED_MODES.has(m));
}

Try / catch

try {
  new Request(url, { mode });
} catch (err) {
  if (err instanceof TypeError && err.message.includes("navigate")) {
    new Request(url); // mode omitted, defaults to cors
  } else throw err;
}

Prevention

When it happens

Trigger: new Request(url, { mode: "navigate" }); mode values forwarded from a UI/config that lets users pick any spec-listed mode.

Common situations: Copy-pasting browser navigation code into a Deno worker; config schemas that enumerate the four spec modes including navigate; attempting to fetch a page "as a navigation" to get no-CORS semantics.

Related errors


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

Appendix: source

Thrown at ext/fetch/23_request.js:450

          (parsedReferrer.protocol === "about:" &&
            parsedReferrer.pathname === "client")
        ) {
          request.referrer = "client";
        } else {
          request.referrer = parsedReferrer.href;
        }
      }
    }

    // 18. referrerPolicy
    if (init.referrerPolicy !== undefined) {
      request.referrerPolicy = init.referrerPolicy;
    }

    // 19. mode
    if (init.mode !== undefined) {
      if (init.mode === "navigate") {
        throw new TypeError("Request mode 'navigate' is not allowed");
      }
      request.mode = init.mode;
    }

    // 20. credentials
    if (init.credentials !== undefined) {
      request.credentialsMode = init.credentials;
    }

    // 21. cache
    if (init.cache !== undefined) {
      request.cacheMode = init.cache;
    }

    // If request's cache mode is "only-if-cached" and request's mode is not
    // "same-origin", then throw a TypeError.
    if (
      request.cacheMode === "only-if-cached" && request.mode !== "same-origin"

View on GitHub (pinned to 9ad36f7a2c)