PouchDB TypeError: Cannot set property ‘_rev’ of undefined

Macro Programming Code on Screent

I faced this strange defect with PouchDB. Turns out its related to database corruption in dev environment caused by hotloading and killing the browser for rapid development purposes. This StackOverflow post led me to realise the local PouchDB is corrupted.

Full Stacktrace for PouchDB TypeError

C:\Users\danie\Documents\repos\noteapp\app\node_modules\pouchdb\lib\index.js:5651
              doc.doc._rev = doc.value.rev;
                           ^

TypeError: Cannot set property '_rev' of undefined
    at allDocsInner (C:\Users\danie\Documents\repos\noteapp\app\node_modules\pouchdb\lib\index.js:5651:28)
    at C:\Users\danie\Documents\repos\noteapp\app\node_modules\pouchdb\lib\index.js:5681:15
    at C:\Users\danie\Documents\repos\noteapp\app\node_modules\pouchdb\lib\index.js:4135:9
    at C:\Users\danie\Documents\repos\noteapp\app\node_modules\pouchdb\lib\index.js:3966:13
[8600:0418/220552.829:ERROR:CONSOLE(131)] "Extension server error: Operation failed: file:///C:/Users/danie/Documents/repos/noteapp/app/app.html has no execution context", source: devtools://devtools/bundled/extensions/ExtensionServer.js (131)
[8600:0418/220552.829:ERROR:CONSOLE(131)] "Extension server error: Operation failed: file:///C:/Users/danie/Documents/repos/noteapp/app/app.html has no execution context", source: devtools://devtools/bundled/extensions/ExtensionServer.js (131)
[8600:0418/220552.837:ERROR:CONSOLE(131)] "Extension server error: Operation failed: file:///C:/Users/danie/Documents/repos/noteapp/app/app.html has no execution context", source: devtools://devtools/bundled/extensions/ExtensionServer.js (131)
[8600:0418/220552.837:ERROR:CONSOLE(40)] "[object Object]", source: chrome-extension://react-developer-tools/build/main.js (40)
C:\Users\danie\Documents\repos\noteapp\app\node_modules\pouchdb\lib\index.js:5651
              doc.doc._rev = doc.value.rev;
                           ^

TypeError: Cannot set property '_rev' of undefined
    at allDocsInner (C:\Users\danie\Documents\repos\noteapp\app\node_modules\pouchdb\lib\index.js:5651:28)
    at C:\Users\danie\Documents\repos\noteapp\app\node_modules\pouchdb\lib\index.js:5681:15
    at C:\Users\danie\Documents\repos\noteapp\app\node_modules\pouchdb\lib\index.js:4135:9
    at C:\Users\danie\Documents\repos\noteapp\app\node_modules\pouchdb\lib\index.js:3966:13
× 「wdm」:

To resolve this, you have to delete the local database using PouchDB’s destroy method as detailed in the docs. This will properly delete the local database. When it is done, remove the destory line. Deleting the Electron app directory in AppData does not help for some reason as I tried that multiple times before realising the database must be formally destroyed and recreated.

Only proceed with this if:

  1. You have a data backup
  2. You have a local DB that is set up to replicate to the remote DB.

DELETING DATABASES IS SCARY: Do not use this option if your PouchDB object has been initialised with a remote database URL. In that case it acts as an API to the remote database. Destroying it will DELETE the remote database.

export const notesDB = new PouchDB('data/notes'); // local database being synced with remote

notesDB.destroy().then((info) => {console.log(info);}).catch(((err) => {console.log(err);}))

Related posts

Fixing Parse Server Request Entity Too Large Error with Node.js and JavaScript: Troubleshooting Permission Errors

Taking playlist randomisation into my own hands – using Javascript to improve Spotify’s Broken Shuffle

Generating JavaScript API Clients from Open API specifications.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Read More