{"record":{"id":"3146c7cfaa98c619","repo":"tursodatabase/turso","slug":"unable-to-get-database-path-for-this-platform-mak","errorCode":null,"errorMessage":"Unable to get database path for this platform. Make sure the native module is properly loaded.","messagePattern":"Unable to get database path for this platform\\. Make sure the native module is properly loaded\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"bindings/react-native/src/index.ts","lineNumber":96,"sourceCode":"\n/**\n * Helper function to construct a database path in a writable directory.\n *\n * @param filename - Database filename (e.g., 'mydb.db')\n * @returns Absolute path to the database file\n *\n * @example\n * ```ts\n * import { getDbPath, connect } from '@tursodatabase/sync-react-native';\n *\n * const dbPath = getDbPath('mydb.db');\n * const db = await connect({ path: dbPath });\n * ```\n */\nexport function getDbPath(filename: string): string {\n  const basePath = paths.database;\n  if (!basePath || basePath === '.') {\n    throw new Error(\n      'Unable to get database path for this platform. ' +\n      'Make sure the native module is properly loaded.'\n    );\n  }\n  return `${basePath}/${filename}`;\n}\n\n/**\n * Connect to a database asynchronously (matches JavaScript bindings API)\n *\n * This is the main entry point for the SDK, matching the API from\n * @tursodatabase/sync-native and @tursodatabase/database-native.\n *\n * **Path handling**: Relative paths are automatically placed in writable directories:\n * - Android: app's database directory (`/data/data/com.app/databases/`)\n * - iOS: app's documents directory\n *\n * Absolute paths and `:memory:` are used as-is.","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/react-native/src/index.ts#L78-L114","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before - unconditional call throws on unsupported platforms\nconst dbPath = getDbPath('mydb.db');\n\n// after\nimport { Platform } from 'react-native';\nconst db = await connect({\n  path: Platform.OS === 'ios' || Platform.OS === 'android'\n    ? getDbPath('mydb.db')\n    : `${documentDir}/mydb.db`, // e.g. expo-file-system documentDirectory\n});","handlingStrategy":"validation","validationCode":"import { paths } from '@tursodatabase/sync-react-native';\n\nexport function safeDbPath(filename: string, documentDir: string): string {\n  const base = paths.database;\n  if (!base || base === '.') return `${documentDir}/${filename}`; // expo-file-system / RNFS dir\n  return `${base}/${filename}`;\n}","typeGuard":"function platformHasDbPath(base: string): boolean {\n  return typeof base === 'string' && base.length > 0 && base !== '.';\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["react-native","platform","file-paths","configuration"],"backgroundTag":"platform-not-supported","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}