react-native-sqlite-storage: TypeError: Cannot read property 'open' of undefined
Expected Behavior
I’m trying to run the following Jest test:
const SQLite = require('react-native-sqlite-storage');
it('can connect to the DB', async () => {
    SQLite.enablePromise(true);
    const db = await SQLite.openDatabase({name: 'file.sqlite3', location: 'default'});
    const status = await db.close();
    expect(status).not.toBeNull();
});
My expectation is that the test either fails because it can’t open the database, or passes because it opens the database then closes it.
Current Behavior
    TypeError: Cannot read property 'open' of undefined
      at Object.exec (node_modules/react-native-sqlite-storage/lib/sqlite.core.js:88:3)
      at SQLitePlugin.open (node_modules/react-native-sqlite-storage/lib/sqlite.core.js:285:12)
      at new SQLitePlugin (node_modules/react-native-sqlite-storage/lib/sqlite.core.js:116:8)
      at SQLiteFactory.call (node_modules/react-native-sqlite-storage/lib/sqlite.core.js:784:10)
      at SQLiteFactory.<anonymous> (node_modules/react-native-sqlite-storage/lib/sqlite.core.js:77:18)
      at node_modules/react-native-sqlite-storage/sqlite.js:72:24
      at tryCallTwo (node_modules/promise/lib/core.js:45:5)
      at doResolve (node_modules/promise/lib/core.js:200:13)
      at new Promise (node_modules/promise/lib/core.js:66:3)
      at SQLiteFactory.plugin.<computed>.<computed> [as openDatabase] (node_modules/react-native-sqlite-storage/sqlite.js:59:21)
Steps to Reproduce (for bugs)
Run the test described above
Context
I’m just trying to get started.
Your Environment
- React Native SQLite Storage Version used: 4.1.0
 - React Native version used: 0.61.5
 - Operating System and version (simulator or device): Android simulator, API level 29
 - IDE used: VSCode
 - Link to your project:
 
Debug logs
See the pasted backtrace above.
About this issue
- Original URL
 - State: open
 - Created 4 years ago
 - Reactions: 1
 - Comments: 16 (2 by maintainers)
 
This is a symptom of bad configuration. Please revisit your installation steps.
I have the same problem😔
The problem can be solved by repackaging the installation package with Android Studio. No operation is required for react-native version above 0.6 My versions: “react”: “18.1.0”, “react-native”: “0.70.5”, “react-native-sqlite-storage”: “^6.0.1”,
I had the same error, and after tracing through sqlite.core.js, the error seems to be on this line https://github.com/andpor/react-native-sqlite-storage/blob/b6aeac439b9d038bbb9d2e16812d512c38246775/lib/sqlite.core.js#L89.
NativeModules["SQLite"]is undefined. My app is made with Expo, and I’m running the web version for development/testing. Is that the problem here? Is there something special required to getNativeModules["SQLite"]to work on expo web?EDIT: Based on this SO Post, it looks like you can’t use this library and Expo. I’ll be switching to expo-sqlite as that is intended for use with Expo, @iamleeg this might solve your issue too.
I’m having a bunch of issues like this one as well - I’m using RN 0.61
It kinda works when using callbacks, but when trying to use promises it throws.