-1

I am trying to replicate a remote CouchDB database with PouchDB. Here is the replication call

try {
        await PouchDB.replicate(sourceDB, targetDB);
        console.log(`Replication complete!`);
    } catch (err) {
        console.error(`Replication failed with error ${err}`);
        throw err;
    }

The database (sourceDB) is quite large (around 8.2k docs and 28k deleted docs, for a total of 16.6MB).

When calling the above, the replication always fails after around 10.4MB of data have been copied to targetDB.

The exception says:

Replication failed with error {"name":"Error","message":"invalid json response body at http://my-db-url/_bulk_docs reason: Unexpected token < in JSON at position 0"}

I am using PouchDB 7.2.2 and CouchDB 3.1.0

Buddyshot
  • 1,614
  • 1
  • 17
  • 44
  • With little information to work with, I recommend hooking into all the [replication](https://pouchdb.com/api.html#replication) event emitters (particularly the 'change' event) to generate a log which you may analyze. – RamblinRose Aug 26 '21 at 12:41

1 Answers1

0

The error message Unexpected token < in JSON at position 0" indicates that the data coming back from the server some time over the process is not in JSON format but probably containing HTML (starting with a tag like <html>).

This may be happening if you server is somehow getting overloaded during sync and sends back an error as an html page.

Try opening the Network tab of the Developer Console and look at the requests, finding the one that fails. Checking its body can give you more information about what is actually happening.

sleidig
  • 1,350
  • 12
  • 28