react-native-sqlite-storage icon indicating copy to clipboard operation
react-native-sqlite-storage copied to clipboard

TypeError: Cannot read property 'open' of undefined

Open iamleeg opened this issue 5 years ago • 16 comments

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.

iamleeg avatar Jan 17 '20 16:01 iamleeg

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

BuckUbel avatar Jan 26 '20 15:01 BuckUbel

I have the same problem😔

zhangwenjie1996 avatar Feb 17 '20 06:02 zhangwenjie1996

This is a symptom of bad configuration. Please revisit your installation steps.

andpor avatar Feb 17 '20 12:02 andpor

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?

iamleeg avatar Feb 17 '20 15:02 iamleeg

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?

zhangwenjie1996 avatar Feb 18 '20 04:02 zhangwenjie1996

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.

gbbarroso avatar Feb 19 '20 10:02 gbbarroso

The same problem, anyone can fix it? :(

Sotatek-SonNguyen2 avatar Apr 04 '21 17:04 Sotatek-SonNguyen2

I have the same issue, any solution ?

shaheryarCS avatar Nov 04 '21 05:11 shaheryarCS

So, no solution for this?

codeshinobi avatar Dec 15 '21 13:12 codeshinobi

● 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

prasanna-col avatar Feb 24 '22 09:02 prasanna-col

No, @andpor could still help by answering my follow-on questions.

iamleeg avatar Feb 24 '22 12:02 iamleeg

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.

andpor avatar Feb 24 '22 15:02 andpor

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.

ROODAY avatar Apr 23 '22 22:04 ROODAY

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",

koger23 avatar May 21 '22 21:05 koger23

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",

CapableOfOperation avatar Feb 02 '23 06:02 CapableOfOperation

I have the same issue, any solution for this ?

AhmedMustafa505 avatar Aug 08 '23 07:08 AhmedMustafa505