marmelab/react-admin · error
The dataProvider is not initialized.
Error message
The dataProvider is not initialized.
What it means
In ra-data-local-forage, the internal localForage persistence helper writes the current in-memory data for a resource to IndexedDB/localStorage. It throws when the in-memory `data` cache has not been populated yet — the provider factory hasn't finished initialization. This signals a lifecycle/initialization bug in the provider itself.
Source
Thrown at packages/ra-data-local-forage/src/index.ts:95
initializePromise = initializeProvider();
}
return initializePromise;
};
const initializeProvider = async () => {
const localForageData = await getLocalForageData();
data = localForageData ?? defaultData;
baseDataProvider = fakeRestProvider(
data,
loggingEnabled
) as DataProvider;
};
// Persist in localForage
const updateLocalForage = (resource: string) => {
if (!data) {
throw new Error('The dataProvider is not initialized.');
}
localforage.setItem(
`${prefixLocalForageKey}${resource}`,
data[resource]
);
};
return {
// read methods are just proxies to FakeRest
getList: async <RecordType extends RaRecord = any>(
resource: string,
params: GetListParams
) => {
await initialize();
if (!baseDataProvider) {
throw new Error('The dataProvider is not initialized.');
}
return baseDataProviderView on GitHub (pinned to 051f511bb0)
Solutions
- Always await the async localForage provider factory before passing it to <Admin dataProvider={...}>.
- Do not invoke the provider's mutation methods directly before initialization; route calls through react-admin after mount.
- Check for code that captured the unfinished provider object and calls it early.
- Upgrade ra-data-local-forage; modern versions initialize before returning the provider.
Example fix
// before
const dp = localForageProvider({ localStorageUpdateTransform: fn });
<Admin dataProvider={dp}>
// after
<Admin dataProvider={localForageProvider({ localStorageUpdateTransform: fn })}> Defensive patterns
Strategy: try-catch
Validate before calling
// ensure the provider is fully initialized before use
const dataProvider = await localForageProvider({ dataProvider: baseDataProvider });
if (typeof dataProvider.update !== 'function') throw new Error('provider not ready'); Type guard
function isInitializedDataProvider(dp: any): dp is DataProvider {
return dp != null && typeof dp.getList === 'function' && typeof dp.update === 'function';
} Try / catch
try {
await dataProvider.update(resource, params);
} catch (e) {
if (e.message === 'The dataProvider is not initialized.') {
// re-run init or surface a loading error
} else throw e;
} Prevention
- Always await localForageProvider before passing it to <Admin>.
- Never store the pre-init provider reference for direct calls.
- Check the browser console for earlier init errors.
- Keep ra-data-local-forage current.
When it happens
Trigger: Calling a mutating method (create/update/delete) before the async initialization (loading data from localForage and the base data provider) has completed, causing updateLocalForage to run with `data === undefined`.
Common situations: Using the provider before the async factory promise resolves (calling the sync-looking function directly instead of awaiting localForageTestable/localForageProvider); calling mutation methods from outside react-admin's lifecycle very early at app startup.
Related errors
- The dataProvider threw an error. It should return a rejected
- The i18nProvider returned a Promise for the messages of the
- The returnPromise parameter can only be used if the mutation
AI-assisted analysis of marmelab/react-admin@051f511bb0 (2026-08-30).
Data as JSON: /api/errors/8643b8c096d44db9.
Report an issue: GitHub.