lbjlaq/Antigravity-Manager · error · Error
common.tauri_api_not_loaded
Error message
common.tauri_api_not_loaded
What it means
ensureTauriEnvironment throws this when the injected Tauri invoke API is not available as a function. It guards calls to Tauri commands so the UI fails fast with an i18n message instead of crashing with 'invoke is not a function'. Note the source comments that in Web mode request is also a function, so this throw only fires when the module's import failed entirely.
Solutions
- Verify src/utils/request.ts exports a callable `request` and that the import path in accountService.ts is correct
- Rebuild the app so the Tauri/web invoke shim is bundled (check bundler aliases and tree-shaking config)
- Confirm which mode the app runs in (Tauri vs web) and ensure web mode routes through the HTTP mapping in request.ts
- Replace the throw with a clearer error naming the missing module for easier diagnosis
Example fix
// before
if (typeof invoke !== 'function') {
throw new Error(i18n.t('common.tauri_api_not_loaded'));
}
// after
if (typeof invoke !== 'function') {
throw new Error(`Tauri invoke bridge missing: got ${typeof invoke}. Check import of ../utils/request`);
} Defensive patterns
Strategy: try-catch
Validate before calling
if (typeof invoke !== 'function') { console.warn('Tauri bridge unavailable; skipping native call'); } Type guard
const isInvokable = (f: unknown): f is (...a: unknown[]) => Promise<unknown> => typeof f === 'function';
Try / catch
try { await startOAuthLogin(); } catch (e) { if (e?.message === i18n.t('common.tauri_api_not_loaded')) { showWebFallback(); } else throw e; } Prevention
- Always import the invoke bridge via the same wrapper module
- Add a startup smoke test asserting the bridge is callable in both Tauri and web builds
- Gate Tauri-only features behind a runtime capability check
When it happens
Trigger: Calling startOAuthLogin, completeOAuthLogin or cancelOAuthLogin in a context where ../utils/request did not resolve to a callable (broken import, bundling issue, or running outside both Tauri and the Web request shim).
Common situations: Opening the bundle in a plain browser without the request shim wired up; a refactor renamed/removed the request export; a build misconfiguration tree-shook the invoke bridge.
Understand the failure class
Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.
AI-assisted analysis of lbjlaq/Antigravity-Manager@90a2b6b207 (2026-09-19).
Data as JSON: /api/errors/edc9f9b7d0d68158.
Report an issue: GitHub.
Appendix: source
Thrown at src/services/accountService.ts:9
import i18n from '../i18n';
import { Account, DeviceProfile, DeviceProfileVersion, QuotaData } from '../types/account';
import { request as invoke } from '../utils/request';
// 检查环境 (可选)
function ensureTauriEnvironment() {
// Web 模式下 request 也是一个 function,所以这里不应抛错
if (typeof invoke !== 'function') {
throw new Error(i18n.t('common.tauri_api_not_loaded'));
}
}
export async function listAccounts(): Promise<Account[]> {
const response = await invoke<any>('list_accounts');
// 如果返回的是对象格式 { accounts: [...] }, 则取其 accounts 属性
if (response && typeof response === 'object' && Array.isArray(response.accounts)) {
return response.accounts;
}
// 否则直接返回响应内容(假设为数组)
return response || [];
}
export async function getCurrentAccount(): Promise<Account | null> {
return await invoke('get_current_account');
}
export async function addAccount(email: string, refreshToken: string): Promise<Account> {View on GitHub (pinned to 90a2b6b207)