Macro Programming Code on Screent
Markus Spiske via Pexels
Home / PouchDB TypeError: Cannot set property ‘_rev’ of undefined
JavaScript

PouchDB TypeError: Cannot set property ‘_rev’ of undefined

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);}))

Leave a Comment

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

DON’T MISS OUT!
Subscribe To Newsletter
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Give it a try, you can unsubscribe anytime.
close-link