sindresorhus/got · error · TypeError

The `url` option is not supported in options objects. Pass i

Error message

The `url` option is not supported in options objects. Pass it as the first argument instead.

What it means

create.ts:45: Got intentionally rejects `{url: ...}` inside an options object. The URL must be the first positional argument (`got(url, options)` or `got(url)`). This forces a clear API shape, prevents ambiguity when merging options, and matches Got's documented contract. The check uses `Object.hasOwn` so even inherited or explicitly-set `url` keys trip it.

Source

Thrown at source/create.ts:45

import type {RequestPromise} from './as-promise/types.js';

const isGotInstance = (value: Got | ExtendOptions): value is Got => is.function(value);

const aliases: readonly HTTPAlias[] = [
	'get',
	'post',
	'put',
	'patch',
	'head',
	'delete',
	'query',
];

const optionsObjectUrlErrorMessage = 'The `url` option is not supported in options objects. Pass it as the first argument instead.';

const assertNoUrlInOptionsObject = (options: Record<string, unknown>): void => {
	if (Object.hasOwn(options, 'url')) {
		throw new TypeError(optionsObjectUrlErrorMessage);
	}
};

const cloneWithProperty = <Value extends Record<string, unknown>>(value: Value, property: string, propertyValue: unknown): Value => {
	const clone = Object.create(Object.getPrototypeOf(value), Object.getOwnPropertyDescriptors(value)) as Value;

	Object.defineProperty(clone, property, {
		value: propertyValue,
		enumerable: true,
		configurable: true,
		writable: true,
	});

	return clone;
};

const create = (defaults: InstanceDefaults): Got => {
	defaults = {

View on GitHub (pinned to e3924aa1e5)

Solutions

  1. Pass the URL as the first argument: `got(url, options)`.
  2. For shared configuration, use `got.extend({prefixUrl, headers, ...})` and pass the path/URL per call.
  3. Pull `url` out of any options-bag before forwarding: `const {url, ...options} = bag; got(url, options)`.
  4. Search for `url:` literals inside objects passed to `got`/`got.extend` and refactor.

Example fix

// before
await got({url: 'https://api.example.com', method: 'POST', json: payload});

// after
await got('https://api.example.com', {method: 'POST', json: payload});
Defensive patterns

Strategy: validation

Validate before calling

function splitUrlArg(bag) {
  if (bag && typeof bag === 'object' && 'url' in bag) {
    const {url, ...options} = bag;
    return [url, options];
  }
  return [bag, undefined];
}
const [url, options] = splitUrlArg(myBag);
await got(url, options);

Type guard

const isUrlInOptions = (o: unknown): o is {url: string | URL} =>
  typeof o === 'object' && o !== null && Object.hasOwn(o, 'url');

Prevention

When it happens

Trigger: Calling `got({url: 'https://x', method: 'GET'})` (passing everything in one object), `got.extend({url: ...})`, or destructuring defaults that carry a `url` key. `assertNoUrlInOptionsObject` runs against both the first arg (if it's a plain object) and the second options arg.

Common situations: Migrating from `request({url, ...})` (the deprecated `request` library used an options-bag style); copy-pasting a config object that bundled url + options; building a generic caller that puts everything in one object.

Related errors


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