pouchdb db.login 不是函数

Posted

技术标签:

【中文标题】pouchdb db.login 不是函数【英文标题】:pouchdb db.login is not a function 【发布时间】:2018-06-29 11:49:55 【问题描述】:

尝试使用这些导入

import PouchDB from 'pouchdb';
import PouchDBAuth from 'pouchdb-authentication';

PouchDB.plugin(PouchDBAuth)

Module ''pouchdb-authentication'' has no default export 是使用这些导入时产生的错误。

PouchDB.plugin(require('pouchdb-authentication'));

使用 require 可以消除错误,但仍然显示 db.login() 不是函数。有人能指出问题出在哪里吗?

【问题讨论】:

也许检查你的插件版本。您的代码应该可以工作; pouchdb-authentication 肯定有一个默认导出。也许再做一次 npm i 这里一样,我可以输出pouchdb-authentication,它有登录功能,但是这行不影响Pouchdb对象:PouchDB.plugin(PouchDBAuth),所以db.login是未定义的 【参考方案1】:

我找到了为什么它在我的情况下不起作用,我正在使用这个:

import '*' as PouchDBAuthentication from 'pouchdb-authentication';

而不是

import PouchDBAuthentication from 'pouchdb-authentication';

所以正确的方法是

import PouchDBAuthentication from 'pouchdb-authentication';
import PouchDB from 'pouchdb';

PouchDB.plugin(PouchDBAuthentication);

另一方面,应执行以下步骤: https://github.com/pouchdb-community/pouchdb-authentication/issues/211

【讨论】:

【参考方案2】:

库下不需要

import PouchAuth from 'pouchdb-authentication';

只需通过身份验证 PouchDb

new PouchDB('url', 
  auth: 
    username: 'user',
    password: 'pass'
  

【讨论】:

以上是关于pouchdb db.login 不是函数的主要内容,如果未能解决你的问题,请参考以下文章

PouchDB 检查本地数据库是不是存在

PouchDB 和 SvelteKit

排毒测试 + React Native + PouchDB 应用程序:由于一些 PouchDB 同步,我们的登录测试一直失败并超时?

PouchDB 结构

复制数据库时 pouchDB 出错

无法将 PouchDB 导入 Angular 5.2.0 应用程序