Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6290

PouchDB sync Error: {"name":"Error","message":"Can't find variable: btoa"}

$
0
0

Hello I have been implementing an off-line database with PouchDB in React Native 0.68.2, although when saving and retrieving the data it works correctly, but when synchronizing it throws this error:

{"name":"Error","message":"Can't find variable: btoa"}
import PouchBD from './pouchDB';export const syncPouchTest = async (nameDB: string) => {  const db = new PouchBD(nameDB, {    adapter: 'react-native-sqlite',  });  try {    const sync = await PouchBD.sync(nameDB, POUCHDB_REMOTE_SERVER); // POUCHDB_REMOTE_SERVER = 'http://localhost:PORT/    console.log('response on on sync data', sync);    return sync;  } catch (error) {    const message = `error on sync pouchDB to ${POUCHDB_REMOTE_SERVER}/${nameDB}\n   === with error: \n${error}`;    console.error(message);    // throw error;  }};

shim.ts file is:

import {shim} from 'react-native-quick-base64';shim();// Avoid using node dependent modulesprocess.browser = true;

pouchDB.ts file have:

import 'react-native-get-random-values';import PouchDB from 'pouchdb-core';import HttpPouch from 'pouchdb-adapter-http';import replication from 'pouchdb-replication';import mapreduce from 'pouchdb-mapreduce';import SQLiteAdapterFactory from 'pouchdb-adapter-react-native-sqlite';import WebSQLite from 'react-native-quick-websql';const SQLiteAdapter = SQLiteAdapterFactory(WebSQLite);export default PouchDB.plugin(HttpPouch)  .plugin(replication)  .plugin(mapreduce)  .plugin(SQLiteAdapter);

CouchDB runs in a docker compose container with the service as follows:

version: "3.8"services:  ...  couchserver:    image: couchdb:3.2.2    restart: always    ports:      - "${COUCHDB_PORT}:5984"    environment:      - COUCHDB_USER=${COUCHDB_USER}      - COUCHDB_PASSWORD=${COUCHDB_PASSWORD}    volumes:        - ./couchdb:/opt/couchdb/data        - ./couchdbData:/opt/couchdb/etc/local.d

I have based on this tutorial: react-native-in-2022-24ej

const testSyncDB = async () => {    const data = {      userInfo: {        name: 'user',        lastName: 'nameExample',        email: 'user@example.com',      },    };    await testPouchDBService('test', data);    // response  {"id": "89d2b549-b734-4862-adc9-e2356b17f448", "ok": true, "rev": "1-620088e18e9bccd447890a2977d2a7ed"}    await syncPouchTest('test');    // response: ERROR: {"name":"Error","message":"Can't find variable: btoa"}  };

Viewing all articles
Browse latest Browse all 6290

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>