{"record":{"id":"1e6276782d78db91","repo":"apify/crawlee","slug":"request-provider-is-not-initialized","errorCode":null,"errorMessage":"Request provider is not initialized!","messagePattern":"Request provider is not initialized!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/basic-crawler/src/internals/basic-crawler.ts","lineNumber":1249,"sourceCode":"            this.#maxRequestsPerCrawl = maxRequestsPerCrawl;\n\n            const isMaxPagesExceeded = () =>\n                this.#maxRequestsPerCrawl && this.#maxRequestsPerCrawl <= this.handledRequestsCount;\n\n            // eslint-disable-next-line prefer-const\n            let { isFinishedFunction, isTaskReadyFunction } = taskLoopOptions;\n\n            // override even if `isFinishedFunction` provided by user - `keepAlive` has higher priority\n            if (keepAlive) {\n                isFinishedFunction = async () => false;\n            }\n\n            const crawlerOwnedTaskLoopConfiguration: Partial<\n                Omit<AutoscaledPoolOptions, 'concurrencySystem' | 'consumer'>\n            > = {\n                runTaskFunction: async () => {\n                    const source = this.requestManager;\n                    if (!source) throw new Error('Request provider is not initialized!');\n\n                    const request = await this.resolveRequest();\n                    if (!request) {\n                        return;\n                    }\n\n                    // Started here, rather than in `handleRequest`, so that a failure during context pipeline\n                    // initialization (e.g. a browser page timing out before the request handler ever runs) is\n                    // still accounted for by `failJob` below - which is a no-op without a matching `startJob`.\n                    this.statistics.startJob(request.id || request.uniqueKey);\n\n                    const crawlingContext = { request } as { request: Request } & Partial<CrawlingContext>;\n                    try {\n                        // The transaction spans the whole pipeline call, covering the navigation hooks\n                        // and `extendContext` too; `handleRequest` drives its outcome explicitly.\n                        await this.runInStorageTransaction(\n                            async () =>\n                                // Navigation, the navigation hooks and the request handler are timed individually, but the","sourceCodeStart":1231,"sourceCodeEnd":1267,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/basic-crawler/src/internals/basic-crawler.ts#L1231-L1267","documentation":"Inside the autoscaled pool's runTaskFunction the crawler reads `this.requestManager`; if it is falsy there is no request provider to pull work from, so the task throws. This is an internal invariant check — under normal operation the constructor always initializes a provider before the pool starts.","triggerScenarios":"The autoscaled pool's runTaskFunction executing while `this.requestManager` is undefined — e.g. due to abnormal initialization order, subclass overriding initialization, or a pool started before the provider was assigned.","commonSituations":"Custom subclasses or partial mocking of BasicCrawler that bypass the constructor's provider setup; race conditions when starting the run loop manually; internal state corruption.","solutions":["Ensure the crawler is constructed and started through the standard `crawler.run()` flow so the request manager is initialized first.","If subclassing, call `super()` and let the base constructor set up the request provider before starting any pool.","Check that no code sets or clears the internal request manager before the crawl starts."],"exampleFix":"// before (subclass skipping base init)\nconstructor(opts) { this.startPool(); }\n// after\nconstructor(opts) { super(opts); this.startPool(); }","handlingStrategy":"try-catch","validationCode":"if (!crawler.requestManager) throw new Error('Crawler has no request provider; call crawler.run() instead of driving internals.');","typeGuard":"function hasProvider(c) { return typeof c === 'object' && c !== null && 'requestManager' in c && c.requestManager != null; }","tryCatchPattern":"try {\n  await crawler.run();\n} catch (err) {\n  if (err.message.includes('Request provider is not initialized')) {\n    // re-create the crawler via its normal constructor and rerun\n  } else throw err;\n}","preventionTips":["Do not drive BasicCrawler internals (autoscaled pool) directly; use crawler.run().","When subclassing, always call super() with the original options.","Avoid mutating crawler private/internal state between construction and run."],"tags":["initialization","request-provider","internal-state"],"backgroundTag":"not-initialized","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}