sindresorhus/got · error · Error

Invalid `responseType` option: ${value as string}

Error message

Invalid `responseType` option: ${value as string}

What it means

Thrown by the `responseType` setter when the value is anything other than `'text'`, `'buffer'`, or `'json'` (or `undefined`, which defaults to `'text'`). The response type drives how Got parses the body, so an unrecognized value would leave parsing undefined and is rejected up front.

Source

Thrown at source/core/options.ts:3317

	// This
	const body = await got(url).json();

	// is semantically the same as this
	const body = await got(url, {responseType: 'json', resolveBodyOnly: true});
	```
	*/
	get responseType(): ResponseType {
		return this.#internals.responseType;
	}

	set responseType(value: ResponseType) {
		if (value === undefined) {
			this.#internals.responseType = 'text';
			return;
		}

		if (value !== 'text' && value !== 'buffer' && value !== 'json') {
			throw new Error(`Invalid \`responseType\` option: ${value as string}`);
		}

		this.#internals.responseType = value;
	}

	get pagination(): PaginationOptions<unknown, unknown> {
		return this.#internals.pagination;
	}

	set pagination(value: PaginationOptions<unknown, unknown>) {
		assert.object(value);

		if (this.#merging) {
			safeObjectAssign(this.#internals.pagination, value);
		} else {
			this.#internals.pagination = value;
		}
	}

View on GitHub (pinned to e3924aa1e5)

Solutions

  1. Use one of `'text'`, `'buffer'`, or `'json'`.
  2. For streaming responses call `got.stream(url)` instead of setting `responseType`.
  3. For raw bytes use `'buffer'` (returns a `Uint8Array`).

Example fix

// before
const data = await got(url, {responseType: 'arraybuffer'});
// after
const data = await got(url, {responseType: 'buffer'});
Defensive patterns

Strategy: type-guard

Validate before calling

const validResponseTypes = new Set(['text','buffer','json','undefined']);
function validateResponseType(value) {
  if (value !== undefined && !validResponseTypes.has(value)) {
    throw new Error(`responseType must be 'text', 'buffer', or 'json'; got ${value}`);
  }
}

Type guard

function isResponseType(v: unknown): v is 'text' | 'buffer' | 'json' | undefined {
  return v === undefined || v === 'text' || v === 'buffer' || v === 'json';
}

Prevention

When it happens

Trigger: Calling `got(url, {responseType: 'arraybuffer'})`, `{responseType: 'stream'}` (use `got.stream(url)` instead), `{responseType: 'raw'}`, or any value outside the three supported strings.

Common situations: Using fetch/axios response type names (`arraybuffer`, `blob`, `document`); typos; passing a value from a config file as a string.

Related errors


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