Reputation: 3159
I have an angular application in which I want to use PouchDB with the PouchDBFind plugin.
I've already gotten PouchDB to work. But I can't figure out how I use the PouchDB Plugin.
Example database setup:
constructor() {
this.db = new PouchDB('exampleDb');
this.db.createIndex({
index: {fields: ['number', 'name']}
}).catch(error => {
console.log(error);
});
}
I always get this error:
ERROR Error: Uncaught (in promise): TypeError: this.db.createIndex is not a function
TypeError: this.db.createIndex is not a function
This is how my import statements are:
import * as PouchDB from 'pouchdb';
import * as PouchFind from 'pouchdb-find';
PouchDB.plugin(PouchFind);
I don't get any errors here.
I've already read about another import alternative, but this does not work:
import PouchDB from 'pouchdb';
import PouchFind from 'pouchdb-find';
I get this error:
"pouchdb-find" has no default export
I have installed the typings. So here are my package.json dependencies:
"dependencies": {
"@types/pouchdb": "6.1.1",
"@types/pouchdb-find": "^0.10.1",
"pouchdb": "^6.2.0",
"pouchdb-find": "^6.3.4"
},
So how do I get the PouchDBFind plugin to work? If any more information are required, please notice me.
Thanks in advance!
Edit: After locking the versions to...
"pouchdb": "6.3.4",
"pouchdb-find": "6.3.4",
... I get the following warning after the webpack compilation:
WARNING in ./src/app/services/example-db/example-db.service.ts
17:8-22 "export 'plugin' (imported as 'PouchDB') was not found in 'pouchdb'
And in the browser console:
ERROR Error: Uncaught (in promise): TypeError: __WEBPACK_IMPORTED_MODULE_2_pouchdb__.plugin is not a function
TypeError: __WEBPACK_IMPORTED_MODULE_2_pouchdb__.plugin is not a function
When I comment the PouchDB.plugin(PouchFind)
line, the warning is gone but the error in the console remains. It just says that it doesn't have a constructor.
Edit: It is an angular-cli project.
Upvotes: 2
Views: 1709
Reputation: 1818
Can you lock your versions to ...
"pouchdb": "6.3.4",
"pouchdb-find": "6.3.4"
... and try again with the following?
import PouchFind from 'pouchdb-find';
import PouchDB from 'pouchdb-browser';
PouchDB.plugin(PouchFind);
Upvotes: 4