cannot open database on react-native-windows: Cannot read properties of undefined (reading 'open')
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')
I was having same issue. Problem fixed when I cleared cache and restart simulator.
npx react-native start --reset-cache
yarn ios
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.
SOLVED: https://github.com/andpor/react-native-sqlite-storage/issues/491#issuecomment-1368515615