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

cannot open database on react-native-windows: Cannot read properties of undefined (reading 'open')

Open aalbaharnah opened this issue 3 years ago • 3 comments

There seems to be an issue that prevents sqlite databse from opening when calling SQLite.openDatabase on windows platform here's the code

import * as React from 'react';
import SQLite from 'react-native-sqlite-storage';

export default function useSqlit() {
    const [isOpen, setIsOpen] = React.useState(false)
    React.useEffect(() => {
        try {
            SQLite.openDatabase({ name: "my.db", location: "default" },
                () => {
                    setIsOpen(true);
                }, () => {
                    // database did not open
                });
        } catch (error) {
            console.log("err: ", error.message)
        }
    });

    return isOpen;
}

Expected Behavior

calling SQLite.openDatabase should open database without errors, so that sql transactions can be executed

Current Behavior

calling SQLite.openDatabase would throw an error that says Cannot read properties of undefined (reading 'open')

Your Environment

"react": "17.0.1",
"react-native": "0.64.2",
"react-native-windows": "^0.64.14",
"react-native-sqlite-storage": "^5.0.0",

Debug logs

Cannot read properties of undefined (reading 'open')

aalbaharnah avatar Sep 07 '21 05:09 aalbaharnah

I was having same issue. Problem fixed when I cleared cache and restart simulator.

npx react-native start --reset-cache

yarn ios

kosick avatar Sep 27 '21 06:09 kosick

Facing the same issue. Getting always error "undefined is not a function". Tried various ways. Is there a working complete example for reference? Thanks in advance.

navinkmishra avatar Sep 06 '22 20:09 navinkmishra

SOLVED: https://github.com/andpor/react-native-sqlite-storage/issues/491#issuecomment-1368515615

MacKenzieHnC avatar Jan 01 '23 19:01 MacKenzieHnC