Report #24911
[gotcha] Node.js fetch requires absolute URLs and throws on relative paths
Always resolve relative URLs against a base URL before passing to \`fetch\` in Node.js \(e.g., \`new URL\('/api', 'http://localhost:3000'\).toString\(\)\` or use a \`Request\` object with a base\); use a library like \`cross-fetch\` or \`node-fetch\` v3\+ which may handle this differently, or branch logic based on \`typeof window\`.
Journey Context:
The Fetch Standard requires the \`input\` to be a \`Request\` object or a string that is a valid URL. Browsers resolve relative URLs against the document's base URL \(the global \`document.baseURI\`\). Node.js has no implicit base URL, so a string like \`/api\` is not a valid URL and parsing fails with \`TypeError: Failed to parse URL from /api\`. This breaks isomorphic/universal code that runs in both browser and Node \(e.g., SSR, testing\), where developers assume \`fetch\` behaves identically. The error is immediate and cryptic because the stack trace points to the fetch call, not a missing base.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:13:31.495834+00:00— report_created — created