require is not defined when using PouchDB filtered replication

500 views Asked by At

I have a bidirectional replication set up between PouchDB and CouchDB and I want to filter the replication so that only relevant documents end up in my local pouch.

pouchDB('medic').sync('http://localhost:5984/medic', {
  live: true,
  retry: true,
  filter: 'medic/doc_by_place'
});

When I execute the sync I get Uncaught ReferenceError: require is not defined from an anonymous function below.

(function () { return function(){return require("lib/app")["filters"]["doc_by_place"].apply(this, arguments);} })()

Where is this coming from and why is require not defined?

1

There are 1 answers

0
Gareth Bowen On BEST ANSWER

This error is coming from the to side of the sync not the from side. Server side filters only make sense on from calls. To filter the to replication execute an adhoc filter function.

I ended up splitting the replication into two as below.

pouchDB('medic')
  .replicate.from('http://localhost:5984/medic', {
    live: true,
    retry: true,
    filter: 'medic/doc_by_place'
  });

pouchDB('medic')
  .replicate.to('http://localhost:5984/medic', {
    live: true,
    retry: true
  });