react-native-sqlite-storage
react-native-sqlite-storage copied to clipboard
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.
I have the same Problem
My Environment
- React Native SQLite Storage Version used: 4.1.0
- React Native version used: 0.61.4
- Operating System and version (simulator or device): Android simulator, API level 29
- IDE used: PHPStorm
I have the same problem😔
This is a symptom of bad configuration. Please revisit your installation steps.
What is badly configured? Which step was missed? What is it in the diagnostic information that led you to this conclusion? What needs updating in the docs to ensure we don’t encounter this again?
The same question. For the reactNative0.61 version and the current react-native-sqlite-storage4.1.0 version, no other configuration is required according to the documentation, so which one is the wrong configuration and which is missing?
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.
The same problem, anyone can fix it? :(
I have the same issue, any solution ?
So, no solution for this?
● Test suite failed to run
TypeError: Cannot read properties of undefined (reading 'open')
14 | import CustomButton from '../utils/CustomButton';
15 |
> 16 | const db = SQLite.openDatabase(
| ^
17 | {
18 | name: 'MainDB',
19 | location: 'default',
at Object.exec (node_modules/react-native-sqlite-storage/lib/sqlite.core.js:88:3)
Did anyone get the solution? @iamleeg
No, @andpor could still help by answering my follow-on questions.
There is nothing meaningful in the provided information that can provide any hints as to what's happening. Have a closer look into the library at Object.exec (node_modules/react-native-sqlite-storage/lib/sqlite.core.js:88:3) and see what could cause the target object to be undefined.
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 get NativeModules["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 had exactly the same problem for days. Then somehow I noticed, that the "react-native-sqlite-storage" is not in package.json somehow... So I installed it (again?!), and that solved it. I hope at least some of you it helps.
(also added types)
My versions: "react": "^17.0.2", "react-native": "0.68.1", "react-native-sqlite-storage": "^6.0.1", "@types/react-native-sqlite-storage": "^5.0.2",
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 have the same issue, any solution for this ?