未捕获(承诺)CustomPouchError ERR_NETWORK_CHANGED

Uncaught (in promise) CustomPouchError ERR_NETWORK_CHANGED

我有一个与托管 couchDB 同步良好的 pouchDB :

sync.company = db.company.sync(companyUrl, {live: true, retry: true})

在我的应用程序中,当我检测到网络不再可用时,我会停止同步:

if (sync.company) sync.company.cancel();

当网络稍后再次恢复时,我的第一步是从远程主机找出最新的更新序列:

PouchDB(companyUrl).info().then(function (info) {... <--uncaught error!

但这会抛出以下错误:

Uncaught (in promise) TypeError: Cannot read property 'length' of undefined
  39.EventEmitter.removeAllListeners    
  (anonymous function)  
  39.EventEmitter.emit  
  39.EventEmitter.removeListener    
  (anonymous function)  
  39.EventEmitter.emit  
  39.EventEmitter.removeListener    
  39.EventEmitter.removeAllListeners    
  39.EventEmitter.removeAllListeners    
  (anonymous function)
OPTIONS <URL>/?_nonce=2isvTJGAXQtX9HWD net::ERR_NETWORK_CHANGED
  ajax  
  ajax  
  HttpPouch 
  (anonymous function)  
  PouchDB   
  PouchDB   
  startSync 
  (anonymous function)  
  $get.Scope.$digest    
  $get.Scope.$apply 
  (anonymous function)  
Uncaught (in promise) CustomPouchError

这一切似乎都从 pouchdb.js 的第 10534 行开始:

if (isFunction(listeners)) {
    this.removeListener(type, listeners);
  } else {
    // LIFO order
    while (listeners.length)  <------!!!!!!!! error starts here !!!!!
      this.removeListener(type, listeners[listeners.length - 1]);
  }
  delete this._events[type];

这是什么意思??

我正在使用 pouchdb 3.2.1

这是 PouchDB 中的错误,已在 master 中修复。特别是,它已由 this commit.

修复

如果你想生活在最前沿,你可以从源代码构建 PouchDB 并使用它:

git clone https://github.com/pouchdb/pouchdb && cd pouchdb && npm install && npm run build

或者等待下一个版本。 :)