andpor / react-native-sqlite-storage

Full featured SQLite3 Native Plugin for React Native (Android and iOS)
MIT License
2.75k stars 521 forks source link

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

Open aalbaharnah opened 3 years ago

aalbaharnah commented 3 years ago

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')

kosick commented 2 years ago

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

npx react-native start --reset-cache

yarn ios

navinkmishra commented 2 years ago

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.

MacKenzieHnC commented 1 year ago

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