mastra-ai/mastra · error
SlackProvider not attached to Mastra. Call __attach() first.
Error message
SlackProvider not attached to Mastra. Call __attach() first.
What it means
SlackProvider.initialize() requires the provider to have been attached to a Mastra instance via __attach(). The #mastra private field is null until that happens, and initialize() throws rather than proceeding, because initialization depends on the instance (storage, agents, server config).
Source
Thrown at channels/slack/src/provider.ts:649
* Only needed if not using Mastra server config.
*/
setBaseUrl(baseUrl: string): void {
this.#baseUrl = stripTrailingSlash(baseUrl);
}
/**
* Restore active Slack installations from storage.
*
* For each active installation in the database, this creates a SlackAdapter
* and injects AgentChannels into the corresponding Agent so it can receive
* Slack events immediately on startup.
*
* Does NOT auto-provision new apps. Use `connect(agentId, options)` to
* create a new Slack app for an agent.
*/
async initialize(): Promise<void> {
if (!this.#mastra) {
throw new Error('SlackProvider not attached to Mastra. Call __attach() first.');
}
// Concurrent callers share the same in-flight initialization
if (this.#initPromise) return this.#initPromise;
this.#initPromise = this.#doInitialize();
try {
await this.#initPromise;
} catch (err) {
// Allow retry on failure
this.#initPromise = null;
throw err;
}
}
async #doInitialize(): Promise<void> {
// Load stored tokens if available (these are fresher than constructor tokens)View on GitHub (pinned to 75dd419e61)
Solutions
- Register the Slack channel through Mastra's channels configuration so the framework calls __attach() for you.
- If managing manually, call provider.__attach(mastra) before provider.initialize().
- Reorder code so initialization happens after the Mastra instance is constructed and attached.
Example fix
// before const provider = new SlackProvider(); await provider.initialize(); // after const provider = new SlackProvider(); provider.__attach(mastra); await provider.initialize();
Defensive patterns
Strategy: try-catch
Validate before calling
if (typeof provider.__attach !== 'function') {
// construct via Mastra channels config so the framework attaches it
}
// Or check indirectly: only call initialize() after Mastra construction. Try / catch
try {
await provider.initialize();
} catch (err) {
if (err instanceof Error && err.message.includes('not attached to Mastra')) {
provider.__attach(mastra);
await provider.initialize();
} else throw err;
} Prevention
- Register Slack through Mastra's channels config instead of instantiating SlackProvider manually.
- Never call initialize() before the Mastra instance exists.
- In tests, replicate the framework's attach step before initializing.
When it happens
Trigger: Calling provider.initialize() directly (or triggering #activateAdapter / #resolveChannelsForInstallation / #autoInitialize) on a SlackProvider that was constructed but never attached to a Mastra instance.
Common situations: Manually instantiating SlackProvider outside the Mastra channel registration flow; calling initialize() in a test before setup; ordering bug where initialize() runs before the framework attaches the provider.
Related errors
- Browser not launched
- App deletion failed: ${data.error}
- GithubIntegration storage has not been initialized.
- GithubIntegration source-control storage has not been initia
- IssueReconcileWorker: call init() before start()
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/f476878b6f4fba66.
Report an issue: GitHub.