tursodatabase/turso · error · Error

Unable to get database path for this platform. Make sure…

Error message

Unable to get database path for this platform. Make sure the native module is properly loaded.

What it means

getDbPath() builds a database file path from paths.database, which falls back through the native constants IOS_DOCUMENT_PATH and ANDROID_DATABASE_PATH and defaults to '.'. If neither constant is present the fallback is '.', and the function throws instead of silently returning a path in the app's CWD (which is not writable anyway). The platform either is not iOS/Android or the loaded native module does not export the path constants.

Solutions

  1. Guard by platform and only call getDbPath on iOS/Android
  2. Or skip it entirely: connect({ path: 'mydb.db' }) already places relative paths in the platform's writable database directory automatically
  3. Pass an explicit absolute path obtained from react-native-fs / expo-file-system if you need control
  4. Rebuild the native module so the path constants are exported (see errors 105/106 for the rebuild steps)

Example fix

// before - unconditional call throws on unsupported platforms
const dbPath = getDbPath('mydb.db');

// after
import { Platform } from 'react-native';
const db = await connect({
  path: Platform.OS === 'ios' || Platform.OS === 'android'
    ? getDbPath('mydb.db')
    : `${documentDir}/mydb.db`, // e.g. expo-file-system documentDirectory
});
Defensive patterns

Strategy: validation

Validate before calling

import { paths } from '@tursodatabase/sync-react-native';

export function safeDbPath(filename: string, documentDir: string): string {
  const base = paths.database;
  if (!base || base === '.') return `${documentDir}/${filename}`; // expo-file-system / RNFS dir
  return `${base}/${filename}`;
}

Type guard

function platformHasDbPath(base: string): boolean {
  return typeof base === 'string' && base.length > 0 && base !== '.';
}

Prevention

When it happens

Trigger: Calling getDbPath('mydb.db') on an unsupported platform (web, windows, mac-catalyst variant without the constants), in a Jest environment where NativeModules.Turso is a mock without IOS_DOCUMENT_PATH/ANDROID_DATABASE_PATH, or with an older/partially linked native build that lacks the constants.

Common situations: Code shared between platforms calling getDbPath unconditionally; unit tests with a stubbed native module; an app reusing a legacy native build after upgrading the JS package that added the constants.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/3146c7cfaa98c619. Report an issue: GitHub.

Appendix: source

Thrown at bindings/react-native/src/index.ts:96

/**
 * Helper function to construct a database path in a writable directory.
 *
 * @param filename - Database filename (e.g., 'mydb.db')
 * @returns Absolute path to the database file
 *
 * @example
 * ```ts
 * import { getDbPath, connect } from '@tursodatabase/sync-react-native';
 *
 * const dbPath = getDbPath('mydb.db');
 * const db = await connect({ path: dbPath });
 * ```
 */
export function getDbPath(filename: string): string {
  const basePath = paths.database;
  if (!basePath || basePath === '.') {
    throw new Error(
      'Unable to get database path for this platform. ' +
      'Make sure the native module is properly loaded.'
    );
  }
  return `${basePath}/${filename}`;
}

/**
 * Connect to a database asynchronously (matches JavaScript bindings API)
 *
 * This is the main entry point for the SDK, matching the API from
 * @tursodatabase/sync-native and @tursodatabase/database-native.
 *
 * **Path handling**: Relative paths are automatically placed in writable directories:
 * - Android: app's database directory (`/data/data/com.app/databases/`)
 * - iOS: app's documents directory
 *
 * Absolute paths and `:memory:` are used as-is.

View on GitHub (pinned to 244cde92a7)