sindresorhus/got · error · TypeError

No URL protocol specified

Error message

No URL protocol specified

What it means

options-to-url.ts:44: if no origin is supplied and `options.protocol` is unset, Got cannot construct a URL — there is no scheme to dial. The parser refuses to guess `http:` vs `https:` because guessing wrong silently breaks TLS enforcement.

Source

Thrown at source/core/utils/options-to-url.ts:44

			throw new TypeError('Parameters `path` and `pathname` are mutually exclusive.');
		}

		if (options.search) {
			throw new TypeError('Parameters `path` and `search` are mutually exclusive.');
		}

		if (options.searchParams) {
			throw new TypeError('Parameters `path` and `searchParams` are mutually exclusive.');
		}
	}

	if (options.search && options.searchParams) {
		throw new TypeError('Parameters `search` and `searchParams` are mutually exclusive.');
	}

	if (!origin) {
		if (!options.protocol) {
			throw new TypeError('No URL protocol specified');
		}

		origin = `${options.protocol}//${options.hostname ?? options.host ?? ''}`;
	}

	const url = new URL(origin);

	if (options.path) {
		const searchIndex = options.path.indexOf('?');
		if (searchIndex === -1) {
			options.pathname = options.path;
		} else {
			options.pathname = options.path.slice(0, searchIndex);
			options.search = options.path.slice(searchIndex + 1);
		}

		delete options.path;
	}

View on GitHub (pinned to e3924aa1e5)

Solutions

  1. Pass a fully-qualified URL: `got('https://api.example.com/users')`.
  2. Or set `prefixUrl` on the instance and pass a path: `got.extend({prefixUrl: 'https://api.example.com'}).get('users')`.
  3. If constructing dynamically, validate the origin is non-empty before calling Got.
  4. Ensure `protocol` (e.g. `'https:'`) is set when building from parts via `hostname`/`pathname`.

Example fix

// before
await got('/users'); // no origin, no protocol

// after
const api = got.extend({prefixUrl: 'https://api.example.com'});
await api.get('users');
Defensive patterns

Strategy: validation

Validate before calling

function assertResolvableUrl(origin, options) {
  if (!origin && !options.protocol) {
    throw new TypeError('Provide an absolute URL or set options.protocol');
  }
}
assertResolvableUrl(origin, myOptions);

Type guard

const hasOriginOrProtocol = (origin: string, o: {protocol?: string}): boolean =>
  Boolean(origin) || Boolean(o.protocol);

Prevention

When it happens

Trigger: Calling Got with only a path (`got('/users')`) without a `prefixUrl` or origin, and not setting `protocol`/`hostname`. Also fires when an empty/undefined origin is passed and `protocol` is missing.

Common situations: Forgetting `prefixUrl` on the instance; passing a relative path where an absolute URL was expected; dynamically building URLs where the origin variable is empty in some env; misconfigured base-URL loader.

Related errors


AI-assisted analysis of sindresorhus/got@e3924aa1e5 (2026-08-03). Data as JSON: /data/errors/b0f0b287fe75fdc7.json. Report an issue: GitHub.