apify/crawlee · error · Error

fetchNextRequest called on an uninitialized crawler

Error message

fetchNextRequest called on an uninitialized crawler

What it means

This internal invariant error means BasicCrawler's fetchNextRequest was invoked before the crawler finished initialization: the requestManager (request provider) is still undefined. It indicates the crawler's internal lifecycle was violated, typically by calling internal methods or racing the crawler before startup.

Source

Thrown at packages/basic-crawler/src/internals/basic-crawler.ts:2606

                        this.log.exception(
                            err,
                            'An unexpected error occurred when the crawler ' +
                                "attempted to persist its request list's state.",
                        );
                    }
                });
            }
        })();

        await Promise.all([requestManagerPersistPromise, this.statistics.persistState?.()]);
    }

    /**
     * Fetches the next request to process from the underlying request provider.
     */
    private async fetchNextRequest() {
        if (this.requestManager === undefined) {
            throw new Error(`fetchNextRequest called on an uninitialized crawler`);
        }

        return this.requestManager.fetchNextRequest();
    }

    /** Handles a single request - runs the request handler with retries, error handling, and lifecycle management. */
    private async handleRequest(crawlingContext: ExtendedContext, requestSource: IRequestManager, request: Request) {
        // An earlier phase we cannot cancel (e.g. a slow `extendContext`) may have run past the internal timeout,
        // which already failed the request in `runTaskFunction`. Bail before running the handler so it does not
        // execute (and re-report) on top of a request the crawler has already moved past.
        if ((crawlingContext as PendingCrawlingContext)[timeoutExpiredKey]?.()) {
            return;
        }

        const statisticsId = request.id || request.uniqueKey;

        // Opened by `runInStorageTransaction`; absent when disabled or when the subclass opens its own.
        const transaction = currentStorageTransaction();

View on GitHub (pinned to dbe57fb09c)

Solutions

  1. Ensure you only interact with the crawler through its public API (run(), addRequests())
  2. If subclassing BasicCrawler, call super lifecycle methods and don't fetch requests before initialization completes
  3. Update Crawlee to the latest version, as this may be an internal race condition bug; report it if reproducible
Defensive patterns

Strategy: try-catch

Try / catch

try { await crawler.run(); } catch (e) { if (/fetchNextRequest called on an uninitialized crawler/.test(String(e.message))) { /* library bug/misuse: report; do not retry blindly */ } else throw e; }

Prevention

When it happens

Trigger: Calling internal/private crawler plumbing (or a subclass overriding lifecycle incorrectly) before run()/initialization completes; a bug or race where the request provider wasn't created before requests were fetched.

Common situations: Subclassing BasicCrawler and overriding _run or initialization steps incorrectly; calling internal APIs from tests; running into a library bug after upgrading versions.

Related errors


AI-assisted analysis of apify/crawlee@dbe57fb09c (2026-08-30). Data as JSON: /api/errors/890a88a3294a3d71. Report an issue: GitHub.