{"record":{"id":"fbad12c6e3abee60","repo":"apify/crawlee","slug":"cannot-create-request-from-type-type","errorCode":null,"errorMessage":"Cannot create Request from type: ${type}","messagePattern":"Cannot create Request from type: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storages/request_list.ts","lineNumber":748,"sourceCode":"    }\n\n    /**\n     * Adds given request.\n     * If the `source` parameter is a string or plain object and not an instance\n     * of a `Request`, then the function creates a `Request` instance.\n     */\n    private addRequest(source: RequestListSource) {\n        let request: Request | RequestOptions;\n        const type = typeof source;\n\n        if (type === 'string') {\n            request = { url: source as string };\n        } else if (source instanceof Request) {\n            request = source;\n        } else if (source && type === 'object') {\n            request = source as RequestOptions;\n        } else {\n            throw new Error(`Cannot create Request from type: ${type}`);\n        }\n\n        const hasUniqueKey = Reflect.has(Object(source), 'uniqueKey');\n        request.uniqueKey ??= Request.computeUniqueKey(request as any);\n\n        // Add index to uniqueKey if duplicates are to be kept\n        if (this.#keepDuplicateUrls && !hasUniqueKey) {\n            request.uniqueKey += `-${this.requests.length}`;\n        }\n\n        const { uniqueKey } = request;\n        this.ensureUniqueKeyValid(uniqueKey);\n\n        // Skip requests with duplicate uniqueKey\n        if (!Object.hasOwn(this.#uniqueKeyToIndex, uniqueKey)) {\n            this.#uniqueKeyToIndex[uniqueKey] = this.requests.length;\n            this.requests.push(request);\n        } else if (this.#keepDuplicateUrls) {","sourceCodeStart":730,"sourceCodeEnd":766,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/core/src/storages/request_list.ts#L730-L766","documentation":"RequestList.addRequest()/addRequests() accepts sources as strings (URLs), Request instances, or plain objects (RequestOptions). When the type of a source item is none of the recognized kinds, the library cannot construct a Request and throws with the detected typeof.","triggerScenarios":"Passing an array of addRequests containing items that are numbers, booleans, null, undefined, arrays, or other unsupported values; passing a non-Request class instance that is neither string nor plain object.","commonSituations":"Mapping over data and accidentally including undefined/null entries; spreading a parsed JSON where items are nested objects with wrong shape (missing url so treated as type mismatch upstream); TypeScript types bypassed with `as any`.","solutions":["Ensure every source item is a URL string, a Request instance, or an object with at least a url property","Filter/validate the array before passing it to addRequests","Fix data mapping that introduces undefined/null items","Enable strict TypeScript typing on the sources array (Array<string | Request | RequestOptions>)"],"exampleFix":"// before\nawait requestList.addRequests([undefined, 'https://x.com']);\n// after\nconst sources = [undefined, 'https://x.com'].filter((s): s is string => typeof s === 'string');\nawait requestList.addRequests(sources);","handlingStrategy":"type-guard","validationCode":"const isSource = (s) => typeof s === 'string' || s instanceof Request || (s && typeof s === 'object' && typeof s.url === 'string');\nsources = sources.filter(isSource);","typeGuard":"function isRequestSource(s) {\n  return typeof s === 'string'\n    || s instanceof Request\n    || (s !== null && typeof s === 'object' && typeof (s).url === 'string');\n}","tryCatchPattern":"try {\n  await requestList.addRequests(sources);\n} catch (err) {\n  if (err.message.startsWith('Cannot create Request from type')) {\n    logger.error(`Bad source item: ${err.message}`);\n  } else throw err;\n}","preventionTips":["Type the sources array as Array<string | Request | RequestOptions>","Filter out null/undefined before adding requests","Let the library construct Requests from URL strings instead of custom objects"],"tags":["validation","request-list","type-error"],"backgroundTag":"invalid-input-type","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}