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
- Guard by platform and only call getDbPath on iOS/Android
- Or skip it entirely: connect({ path: 'mydb.db' }) already places relative paths in the platform's writable database directory automatically
- Pass an explicit absolute path obtained from react-native-fs / expo-file-system if you need control
- 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
- Prefer connect({ path: 'mydb.db' }) - it resolves the writable directory for you
- Only call getDbPath on ios/android; gate shared code with Platform.OS
- In tests, mock the native module's IOS_DOCUMENT_PATH/ANDROID_DATABASE_PATH constants
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
- HTTP request missing URL: no URL in request and no baseUrl…
- Segment size exceeds the native platform size.
- Advanced sync options require a remote embedded replica…
- Advanced sync options require an embedded replica…
- Auth Token requires a remote Turso URL Data Source.
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)