apify/crawlee · error · Error
RequestList is not initialized; you must call "await request
Error message
RequestList is not initialized; you must call "await requestList.initialize()" before using it!
What it means
Most RequestList accessors (getState, fetchNextRequest, markRequestAsHandled, counts, checkReadiness) require initialize() to have completed, because initialization loads/persists requests and state. Any use before that finds the internal structures empty, so the library throws this explicit reminder.
Source
Thrown at packages/core/src/storages/request_list.ts:797
throw new Error("Request object's uniqueKey must be a non-empty string");
}
}
/**
* Checks that a request is currently being processed and throws an error if not.
*/
private ensureInProgress(uniqueKey: string): void {
if (!this.inProgress.has(uniqueKey)) {
throw new Error(`The request is not being processed (uniqueKey: ${uniqueKey})`);
}
}
/**
* Throws an error if request list wasn't initialized.
*/
private ensureIsInitialized(): void {
if (!this.#isInitialized) {
throw new Error(
'RequestList is not initialized; you must call "await requestList.initialize()" before using it!',
);
}
}
/**
* Returns the total number of unique requests present in the `RequestList`.
*/
async getTotalCount(): Promise<number> {
this.ensureIsInitialized();
return this.requests.length;
}
/**
* Returns the number of pending requests in the `RequestList`.
*/
async getPendingCount(): Promise<number> {View on GitHub (pinned to dbe57fb09c)
Solutions
- await requestList.initialize() once before any other usage (open()/static helpers usually do this for you)
- Do not pass the list to consumers before initialization resolves
- Handle initialize() rejections so failure does not silently lead to later calls
- Prefer RequestList.open() which handles initialization internally
Example fix
// before
const requestList = new RequestList({ sources });
const request = await requestList.fetchNextRequest(); // throws
// after
const requestList = new RequestList({ sources });
await requestList.initialize();
const request = await requestList.fetchNextRequest(); Defensive patterns
Strategy: validation
Validate before calling
if (!requestList.checkReadiness?.().isReady /* or track your own flag */) {
throw new Error('Initialize the RequestList before use');
} Type guard
null
Try / catch
try {
const req = await requestList.fetchNextRequest();
} catch (err) {
if (err.message.includes('not initialized')) {
await requestList.initialize();
const req = await requestList.fetchNextRequest();
} else throw err;
} Prevention
- Always await initialize() (or use RequestList.open()) before any other call
- Wrap construction+initialization in a single async factory function
- Never share a RequestList instance before its initialization promise resolves
When it happens
Trigger: Calling fetchNextRequest(), getTotalCount(), getPendingCount(), getState(), markRequestAsHandled(), or checkReadiness() before awaiting initialize(); forgetting the await on initialize(); initialize() rejected but code continued.
Common situations: Constructing a RequestList in a helper and returning it before initialization; racing initialization in parallel async code; refactoring where the await was dropped; using a list inside a handler registered before startup completes.
Related errors
- OwnedOrInjected value is not initialized yet
- Cannot set() a borrowed OwnedOrInjected value
- OwnedOrInjected value is already initialized
- Recoverable state has not yet been loaded - call initialize(
- RequestList sources are already loading or were loaded.
AI-assisted analysis of apify/crawlee@dbe57fb09c (2026-08-30).
Data as JSON: /api/errors/9e7b8699a9feea7a.
Report an issue: GitHub.