Angular和PouchDBFind插件
问题描述:
我有一个角度应用程序,我想在PouchDB中使用PouchDBFind插件。Angular和PouchDBFind插件
我已经得到了PouchDB的工作。但我无法弄清楚我如何使用PouchDB插件。
示例数据库设置:
constructor() {
this.db = new PouchDB('exampleDb');
this.db.createIndex({
index: {fields: ['number', 'name']}
}).catch(error => {
console.log(error);
});
}
我总是得到这样的错误:
ERROR Error: Uncaught (in promise): TypeError: this.db.createIndex is not a function
TypeError: this.db.createIndex is not a function
这是我的import语句如何:
import * as PouchDB from 'pouchdb';
import * as PouchFind from 'pouchdb-find';
PouchDB.plugin(PouchFind);
我没有得到任何错误这里。
我已经读到另一进口替代,但这并没有工作:
import PouchDB from 'pouchdb';
import PouchFind from 'pouchdb-find';
我得到这个错误:
"pouchdb-find" has no default export
我已经安装了分型。 因此,这里有我的package.json依赖关系:
"dependencies": {
"@types/pouchdb": "6.1.1",
"@types/pouchdb-find": "^0.10.1",
"pouchdb": "^6.2.0",
"pouchdb-find": "^6.3.4"
},
那么,如何让PouchDBFind插件工作? 如果需要更多信息,请注意我。
在此先感谢!
编辑: 锁定版本...后
"pouchdb": "6.3.4",
"pouchdb-find": "6.3.4",
...我得到的WebPack编译后以下警告:
WARNING in ./src/app/services/example-db/example-db.service.ts
17:8-22 "export 'plugin' (imported as 'PouchDB') was not found in 'pouchdb'
并在浏览器控制台:
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
当我评论PouchDB.plugin(PouchFind)
行,警告消失,但控制台中的错误仍然存在。它只是说它没有构造函数。
编辑:这是一个角度cli项目。
答
您可以锁定版本...
"pouchdb": "6.3.4",
"pouchdb-find": "6.3.4"
...并用以下再试一次吗?
import PouchFind from 'pouchdb-find';
import PouchDB from 'pouchdb-browser';
PouchDB.plugin(PouchFind);
感谢您的回答!我已更新了我的问题。而且我仍然需要像下面那样导入: import * from'pouchdb'作为PouchDB。从'pouchdb'导入PouchDB表示没有默认导出 – Lados
卸载类型并重新安装pouchdb和pouchdb-find后,我可以按照您的建议和所有工作来导入它。谢谢! – Lados
Okey,对不起,我犯了一个错误。导入工作,但我仍然得到这个错误:错误TypeError:__WEBPACK_IMPORTED_MODULE_1_pouchdb__不是一个构造函数 – Lados