seigel / pouchdb-react-native

Pouchdb with async storage

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Invalid Adapter: undefined, js engine: hermes NB! do not use this library

kriit24 opened this issue · comments

It does not work

import PouchDB from 'pouchdb-react-native' const localDB = new PouchDB('myDB') console.log(localDB.adapter)

ERROR:

ERROR Error: Invalid Adapter: undefined, js engine: hermes

Yeah it seems to be the asyncstorage has been removed from react-native latest versions.
AsyncStoragePouch.valid = () => { try { return require('@react-native-async-storage/async-storage').default !== null } catch (error) { return false } }
quick fix change the asyncstorage from react-native to @react-native-async-storage/async-storage
node_modules/pouchdb-adapter-asyncstorage/src/index.js then run npx patch-package pouchdb-adapter-asyncstorage

I think I made all the changes correctly, this is my node_modules/pouchdb-adapter-asyncstorage/src/index.js:

'use strict'

import './polyfill'

// API implementations
import allDocs from './all_docs'
import bulkDocs from './bulk_docs'
import changes from './changes'
import destroy from './destroy'
import doCompaction from './do_compaction'
import get from './get'
import getAttachment from './get_attachment'
import getRevisionTree from './get_revision_tree'
import info from './info'

import { get as getDatabase, close as closeDatabase } from './databases'

const ADAPTER_NAME = 'asyncstorage'

function AsyncStoragePouch (dbOpts, constuctorCallback) {
  const api = this

  api._remote = false
  api.type = () => ADAPTER_NAME

  api._id = callback => {
    getDatabase(dbOpts)
      .then(database => sequence(cb => cb(null, database.meta.db_uuid), callback))
      .catch(callback)
  }
  api._info = callback => {
    getDatabase(dbOpts)
      .then(database => sequence(cb => info(database, cb), callback))
      .catch(callback)
  }
  api._get = (id, opts, callback) => {
    getDatabase(dbOpts)
      .then(database => sequence(cb => get(database, id, opts, cb), callback))
      .catch(callback)
  }
  api._getAttachment = (docId, attachId, attachment, opts, callback) => {
    getDatabase(dbOpts)
      .then(database => sequence(cb => getAttachment(database, docId, attachId, attachment, opts, cb), callback))
      .catch(callback)
  }
  api._getRevisionTree = (id, callback) => {
    getDatabase(dbOpts)
      .then(database => sequence(cb => getRevisionTree(database, id, cb), callback))
      .catch(callback)
  }
  api._allDocs = (opts, callback) => {
    getDatabase(dbOpts)
      .then(database => sequence(cb => allDocs(database, opts, cb), callback))
      .catch(callback)
  }
  api._bulkDocs = (req, opts, callback) => {
    getDatabase(dbOpts)
      .then(database => sequence(cb => bulkDocs(database, req, opts, cb), callback))
      .catch(callback)
  }
  api._changes = opts => {
    getDatabase(dbOpts)
      .then(database => sequence(cb => {
        changes(database, api, opts)
        cb()
      }))
      .catch(error => opts.complete && opts.complete(error))
  }
  api._doCompaction = (id, revs, callback) => {
    getDatabase(dbOpts)
      .then(database => sequence(cb => doCompaction(database, id, revs, cb), callback))
      .catch(callback)
  }
  api._destroy = (opts, callback) => {
    getDatabase(dbOpts)
      .then(database => sequence(cb => destroy(database, opts, cb), callback))
      .catch(callback)
  }
  api._close = callback => {
    sequence(cb => {
      closeDatabase(dbOpts.name)
      cb()
    }, callback)
  }

  constuctorCallback(null, api)

  const queue = []
  let isRunning = false
  const sequence = (func, callback) => {
    const run = () => {
      if (isRunning || queue.length === 0) return

      isRunning = true
      const task = queue.shift()
      setImmediate(() => {
        task.func((error, result) => {
          task.callback && task.callback(error, result)
          isRunning = false
          run()
        })
      })
    }

    queue.push({func, callback})
    run()
  }
}

AsyncStoragePouch.valid = () => { 
  try { 
    return require('@react-native-async-storage/async-storage').default !== null 
  } catch (error) { 
    return false 
  }
}

AsyncStoragePouch.use_prefix = false

export default function (PouchDB) {
  PouchDB.adapter(ADAPTER_NAME, AsyncStoragePouch, true)
}

this is my basic code:

import PouchDB from 'pouchdb-react-native';

const db = new PouchDB('mydb');

and this is my package.json:

{
	"name": "ssense-mobile-app",
	"version": "1.0.0",
	"main": "node_modules/expo/AppEntry.js",
	"scripts": {
		"start": "expo start",
		"android": "expo run:android",
		"ios": "expo run:ios",
		"web": "expo start --web"
	},
	"dependencies": {
		"@react-native-community/masked-view": "^0.1.11",
		"@react-navigation/bottom-tabs": "^6.5.20",
		"@react-navigation/native": "^6.1.17",
		"@react-navigation/native-stack": "^6.9.26",
		"@reduxjs/toolkit": "^2.2.3",
		"expo": "^51.0.5",
		"expo-camera": "^15.0.8",
		"expo-image": "~1.12.9",
		"expo-location": "~17.0.1",
		"expo-network": "~6.0.1",
		"expo-notifications": "~0.28.1",
		"pouchdb-react-native": "^6.4.1",
		"react": "18.2.0",
		"react-native": "0.74.2",
		"react-native-calendars": "^1.1304.1",
		"react-native-gesture-handler": "~2.16.1",
		"react-native-maps": "1.14.0",
		"react-native-reanimated": "3.10.0",
		"react-native-safe-area-context": "4.10.1",
		"react-native-screens": "3.31.1",
		"react-native-timeline-flatlist": "^0.8.0",
		"react-native-vector-icons": "^10.0.3",
		"react-redux": "^9.1.1"
	},
	"devDependencies": {
		"@babel/core": "^7.20.0"
	},
	"private": true
}

here the errors:
TypeError: property is not configurable, js engine: hermes
ERROR Error: Invalid Adapter: undefined, js engine: hermes

i don't know why doesn't work!
please, i'd like to have support from you!