{"id":"26abb873088bb748","repo":"sindresorhus/got","slug":"missing-url-property","errorCode":null,"errorMessage":"Missing `url` property","messagePattern":"Missing `url` property","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"source/core/index.ts","lineNumber":393,"sourceCode":"\t\t\t\t\t}\n\n\t\t\t\t\tthis.options.setPipedHeader(normalizedHeader, value);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tthis.on('newListener', event => {\n\t\t\tif (event === 'retry' && this.listenerCount('retry') > 0) {\n\t\t\t\tthrow new Error('A retry listener has been attached already.');\n\t\t\t}\n\t\t});\n\n\t\ttry {\n\t\t\tthis.options = new Options(url, options, defaults);\n\n\t\t\tif (!this.options.url) {\n\t\t\t\tif (this.options.prefixUrl === '') {\n\t\t\t\t\tthrow new TypeError('Missing `url` property');\n\t\t\t\t}\n\n\t\t\t\tthis.options.url = '';\n\t\t\t}\n\n\t\t\tthis.requestUrl = this.options.url as URL;\n\n\t\t\t// Publish request creation event\n\t\t\tpublishRequestCreate({\n\t\t\t\trequestId: this._requestId,\n\t\t\t\turl: getSanitizedUrl(this.options),\n\t\t\t\tmethod: this.options.method,\n\t\t\t});\n\t\t} catch (error: unknown) {\n\t\t\tconst {options} = error as OptionsError;\n\t\t\tif (options) {\n\t\t\t\tthis.options = options;\n\t\t\t}","sourceCodeStart":375,"sourceCodeEnd":411,"githubUrl":"https://github.com/sindresorhus/got/blob/e3924aa1e53a6ca3eb93a43618ce532442a89b40/source/core/index.ts#L375-L411","documentation":"Thrown at source/core/index.ts:393 during Request construction. After Options merges the input, got expects a resolvable URL — either from the first argument, from `url`, or composed from `prefixUrl` plus a relative path. If `options.url` is still falsy AND `prefixUrl` is the empty string (the default), there is no base to derive a URL from, so got throws a TypeError. The check is a hard precondition for any HTTP request: without a URL there is nothing to connect to.","triggerScenarios":"Calling `got()` or `got('')` with no URL and no prefixUrl; calling `got({ method: 'GET' })` with only options but no url; calling a got instance created with `got.extend({ method: 'POST' })` and then invoking it without a URL argument.","commonSituations":"Forgetting the URL argument when refactoring a call to pass only an options object; building a got instance with extend() but putting the URL inside extend() (it doesn't accept url there); env-driven code where the URL comes from a config variable that is unexpectedly undefined.","solutions":["Pass a non-empty URL string or URL object as the first argument: `got('https://example.com')`.","Or set `prefixUrl` on the instance (`got.extend({ prefixUrl: 'https://example.com' })`) so relative paths in calls resolve to a full URL.","If the URL comes from configuration, validate it is a non-empty string before invoking got."],"exampleFix":"// before\nawait got({ method: 'GET', headers: { accept: 'application/json' } });\n\n// after\nawait got('https://api.example.com/resource', {\n  method: 'GET',\n  headers: { accept: 'application/json' }\n});\n\n// or via extend\nconst api = got.extend({ prefixUrl: 'https://api.example.com' });\nawait api('resource', { searchParams: { id: 1 } });","handlingStrategy":"validation","validationCode":"function assertUrlProvided(url, options) {\n  const hasUrlArg = typeof url === 'string' && url.length > 0 || url instanceof URL;\n  const hasOptionsUrl = options && typeof options.url === 'string' && options.url.length > 0;\n  const hasPrefixUrl = options && typeof options.prefixUrl === 'string' && options.prefixUrl.length > 0;\n  if (!hasUrlArg && !hasOptionsUrl && !hasPrefixUrl) {\n    throw new TypeError('got requires a url argument or a prefixUrl; received neither');\n  }\n}\n\n// before each call:\nassertUrlProvided(url, options);\nawait got(url, options);","typeGuard":"function isNonEmptyUrl(v: unknown): v is string | URL {\n  if (v instanceof URL) return v.href.length > 0;\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await got(url, options);\n} catch (error) {\n  if (error instanceof TypeError && /Missing `url` property/.test(error.message)) {\n    throw new Error('Configuration error: no URL provided to got. Set prefixUrl or pass a URL.', { cause: error });\n  }\n  throw error;\n}","preventionTips":["Always pass a non-empty URL string/URL object as the first argument, or configure prefixUrl via got.extend.","Validate config-derived URLs are non-empty strings before the call.","got.extend does not accept `url` — set prefixUrl there and pass the path at call time."],"tags":["url","configuration","constructor","validation"],"analyzedSha":"e3924aa1e53a6ca3eb93a43618ce532442a89b40","analyzedAt":"2026-08-03T19:22:24.770Z","schemaVersion":2}