craftzdog / pouchdb-adapter-react-native-sqlite

PouchDB adapter using ReactNative SQLite as its backing store
https://github.com/craftzdog/pouchdb-react-native
MIT License
131 stars 25 forks source link

Undefined is not an object (evaluating 'RNSqlite2.exec') #5

Closed ozmaat closed 6 years ago

ozmaat commented 6 years ago

Hi,

I have the following code but when app starts, an error is thrown.

undefined is not an object (evaluating 'RNSqlite2.exec')
exec
    ..\node_modules\react-native-sqlite-2\src\SQLiteDatabase.js:74:12
runBatch
    ..\node_modules\websql\lib\websql\WebSQLTransaction.js:54:32
runAllSql
    ..\node_modules\websql\lib\websql\WebSQLTransaction.js:96:11
_checkDone
    ..\node_modules\websql\lib\websql\WebSQLTransaction.js:133:12
<unknown>
    ..\node_modules\websql\lib\websql\WebSQLDatabase.js:62:4
run
    ..\node_modules\websql\node_modules\immediate\lib\index.js:71:11
nextTick
    ..\node_modules\websql\node_modules\immediate\lib\index.js:42:6
<unknown>
    ..\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:297:23
_callTimer
    ..\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:154:6
_callImmediatesPass
    ..\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:202:17
callImmediates
    ..\node_modules\react-native\Libraries\Core\Timers\JSTimers.js:466:11
__callImmediates
    ..\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:329:4
<unknown>
    ..\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:147:6
__guardSafe
    ..\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:316:6
flushedQueue
    ..\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:146:17
callFunctionReturnFlushedQueue
    ..\node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:121:11```
import PouchDB from "pouchdb-react-native";
import SQLite from "react-native-sqlite-2";
import SQLiteAdapterFactory from "pouchdb-adapter-react-native-sqlite";

const SQLiteAdapter = SQLiteAdapterFactory(SQLite);
PouchDB.plugin(SQLiteAdapter);

const localDB = new PouchDB("mydb.db", { adapter: "react-native-sqlite" });

Dependencies

 "pouchdb-adapter-react-native-sqlite": "^1.0.3",
    "pouchdb-find": "^6.4.3",
    "pouchdb-react-native": "^6.4.0",
    "react": "16.3.0-alpha.1",
    "react-native": "^0.54.2",
    "react-native-action-button": "^2.8.4",
    "react-native-deprecated-custom-components": "^0.1.2",
    "react-native-sqlite-2": "^1.5.2",
    "react-navigation": "^1.5.8"

If I change the line

const localDB = new PouchDB("mydb.db", { adapter: "react-native-sqlite" });

to

const localDB = new PouchDB("myDB");

It works.

Any ideas what could be the issue.

Thank you

ozmaat commented 6 years ago

Running the react-native link pouchdb-adapter-react-native-sqlite has solved the issue.

And thanks for the module. Great to see the speed boost.

JohnFTitor commented 1 year ago

For me, manually linking the package in the podfile fixes the issue