{"id":"527b488099289a0c","repo":"sindresorhus/got","slug":"the-url-option-is-not-supported-in-options-objec","errorCode":null,"errorMessage":"The `url` option is not supported in options objects. Pass it as the first argument instead.","messagePattern":"The `url` option is not supported in options objects\\. Pass it as the first argument instead\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/create.ts","lineNumber":45,"sourceCode":"import type {RequestPromise} from './as-promise/types.js';\n\nconst isGotInstance = (value: Got | ExtendOptions): value is Got => is.function(value);\n\nconst aliases: readonly HTTPAlias[] = [\n\t'get',\n\t'post',\n\t'put',\n\t'patch',\n\t'head',\n\t'delete',\n\t'query',\n];\n\nconst optionsObjectUrlErrorMessage = 'The `url` option is not supported in options objects. Pass it as the first argument instead.';\n\nconst assertNoUrlInOptionsObject = (options: Record<string, unknown>): void => {\n\tif (Object.hasOwn(options, 'url')) {\n\t\tthrow new TypeError(optionsObjectUrlErrorMessage);\n\t}\n};\n\nconst cloneWithProperty = <Value extends Record<string, unknown>>(value: Value, property: string, propertyValue: unknown): Value => {\n\tconst clone = Object.create(Object.getPrototypeOf(value), Object.getOwnPropertyDescriptors(value)) as Value;\n\n\tObject.defineProperty(clone, property, {\n\t\tvalue: propertyValue,\n\t\tenumerable: true,\n\t\tconfigurable: true,\n\t\twritable: true,\n\t});\n\n\treturn clone;\n};\n\nconst create = (defaults: InstanceDefaults): Got => {\n\tdefaults = {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/sindresorhus/got/blob/e3924aa1e53a6ca3eb93a43618ce532442a89b40/source/create.ts#L27-L63","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass the URL as the first argument: `got(url, options)`.","For shared configuration, use `got.extend({prefixUrl, headers, ...})` and pass the path/URL per call.","Pull `url` out of any options-bag before forwarding: `const {url, ...options} = bag; got(url, options)`.","Search for `url:` literals inside objects passed to `got`/`got.extend` and refactor."],"exampleFix":"// before\nawait got({url: 'https://api.example.com', method: 'POST', json: payload});\n\n// after\nawait got('https://api.example.com', {method: 'POST', json: payload});","handlingStrategy":"validation","validationCode":"function splitUrlArg(bag) {\n  if (bag && typeof bag === 'object' && 'url' in bag) {\n    const {url, ...options} = bag;\n    return [url, options];\n  }\n  return [bag, undefined];\n}\nconst [url, options] = splitUrlArg(myBag);\nawait got(url, options);","typeGuard":"const isUrlInOptions = (o: unknown): o is {url: string | URL} =>\n  typeof o === 'object' && o !== null && Object.hasOwn(o, 'url');","tryCatchPattern":null,"preventionTips":["Always pass the URL as the first positional argument.","Use `got.extend({prefixUrl, ...})` for shared config, not an options bag with `url`.","If migrating from `request`, split `{url, ...rest}` once at the boundary.","Lint for `url:` keys inside objects passed to `got`."],"tags":["url","api-usage","migration"],"analyzedSha":"e3924aa1e53a6ca3eb93a43618ce532442a89b40","analyzedAt":"2026-08-03T19:22:24.770Z","schemaVersion":2}