{"record":{"id":"80b210c8f2854ebc","repo":"laurent22/joplin","slug":"unable-to-determine-database-path","errorCode":null,"errorMessage":"Unable to determine database path.","messagePattern":"Unable to determine database path\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"packages/app-mobile/utils/database-driver-react-native.ts","lineNumber":17,"sourceCode":"import * as SQLite from 'expo-sqlite';\nimport DatabaseDriver, { DatabaseCloseOptions, DatabaseOpenOptions, SqlSelectParams } from '@joplin/lib/database-driver';\nimport * as RNFS from '@dr.pogodin/react-native-fs';\nimport { NativeModules, Platform } from 'react-native';\nimport shim from '@joplin/lib/shim';\nimport { join } from 'path';\n\n// cspell:ignore NSURLI\n\nconst getDatabaseDirectory = async () => {\n\tlet databaseDirectory;\n\tif (Platform.OS === 'ios') {\n\t\tdatabaseDirectory = `${RNFS.LibraryDirectoryPath}/LocalDatabase/`;\n\t} else if (Platform.OS === 'android') {\n\t\tdatabaseDirectory = NativeModules.SystemInformationPackage?.getConstants()?.databaseDirectory;\n\t}\n\tif (!databaseDirectory) throw new Error('Unable to determine database path.');\n\n\tif (!await shim.fsDriver().exists(databaseDirectory)) {\n\t\t// For compatibility with react-native-sqlite-storage, exclude the database\n\t\t// directory from iCloud backups:\n\t\tawait RNFS.mkdir(databaseDirectory, { NSURLIsExcludedFromBackupKey: true });\n\t}\n\treturn databaseDirectory;\n};\n\nexport default class DatabaseDriverReactNative implements DatabaseDriver {\n\tprivate lastInsertId_: string;\n\tprivate db_: SQLite.SQLiteDatabase;\n\tpublic constructor() {\n\t\tthis.lastInsertId_ = null;\n\t}\n\n\tpublic async open(options: DatabaseOpenOptions) {\n\t\tconst database = await SQLite.openDatabaseAsync(","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/laurent22/joplin/blob/981a03c5c9e88130bccff4db47c411d35ec7ae2c/packages/app-mobile/utils/database-driver-react-native.ts#L1-L35","documentation":"The React Native database driver can only resolve the SQLite storage directory via platform-specific APIs: RNFS.LibraryDirectoryPath on iOS or a native SystemInformationPackage constant on Android. If neither yields a path, initialization cannot proceed and the driver throws before opening any database.","triggerScenarios":"Running on iOS when RNFS.LibraryDirectoryPath is undefined, or on Android when the native module `SystemInformationPackage` (or its databaseDirectory constant) is missing — e.g. native module not linked after adding/upgrading dependencies.","commonSituations":"Android builds where native autolinking failed or a clean JS-only rebuild was done without re-linking native modules; Expo/managed environments lacking the custom native module; iOS upgrades changing LibraryDirectoryPath semantics.","solutions":["Rebuild the native app so react-native-fs and SystemInformationPackage are linked (`npx react-native run-android` / clean build).","Verify NativeModules.SystemInformationPackage is available and exposes databaseDirectory on Android.","Check Platform.OS handling — the platform must be 'ios' or 'android'; other platforms are unsupported.","If writing tests, mock the driver/databaseDirectory rather than running this code path."],"exampleFix":"// before (Android: module missing at runtime)\nconst mod = NativeModules.SystemInformationPackage;\n// after\nconst mod = NativeModules.SystemInformationPackage;\nif (!mod?.getConstants?.()?.databaseDirectory) throw new Error('SystemInformationPackage native module not linked — rebuild the app');","handlingStrategy":"try-catch","validationCode":"const dir = Platform.OS === 'ios' ? `${RNFS.LibraryDirectoryPath}/LocalDatabase/` : NativeModules.SystemInformationPackage?.getConstants()?.databaseDirectory;\nif (!dir) throw new Error('databaseDirectory unavailable — native module not linked');","typeGuard":"const hasDatabaseDir = (d: string | undefined | null): d is string => typeof d === 'string' && d.length > 0;","tryCatchPattern":"try { const db = database(); } catch (e) { if (e.message === 'Unable to determine database path.') throw new Error('Rebuild the app: native modules missing'); else throw e; }","preventionTips":["Rebuild native binaries after adding/updating react-native packages","Verify NativeModules.SystemInformationPackage on Android in a debug build","Run pod install on iOS after dependency changes"],"tags":["react-native","database","mobile","platform"],"backgroundTag":"missing-dependency","analyzedSha":"981a03c5c9e88130bccff4db47c411d35ec7ae2c","analyzedAt":"2026-09-17T14:49:40.960Z","contentChangedAt":"2026-09-17T14:49:40.960Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}