jakearchibald / idb

IndexedDB, but with promises
https://www.npmjs.com/package/idb
ISC License
6.39k stars 361 forks source link

can't find variable indexeddb in react native without debugger #133

Closed billtlee closed 5 years ago

billtlee commented 5 years ago

In react native, I have a file call mydb.js

import { openDB, deleteDB, wrap, unwrap } from 'idb';

const dbPromise = openDB('mydb-store', 1, {
  upgrade(db) {
    db.createObjectStore('keyval');
  }
});

export const getItemAsync = async key => {
  return (await dbPromise).get('keyval', key);
};

export const setItemAsync = async (key, val) => {
  return (await dbPromise).put('keyval', val, key);
};

export const deleteItemAsync = async key => {
  return (await dbPromise).delete('keyval', key);
};

export const clear = async () => {
  return (await dbPromise).clear('keyval');
};

export const keys = async () => {
  return (await dbPromise).getAllKeys('keyval');
};

in another file I am calling

import * as MyDB from '../api/mydb';

deviceId = await MyDB.setItemAsync('deviceId', uuidv4());

For some strange reason, if I have remote debugging on, everything works fine. As soon as I turn off debugging, I am getting an error

Can't find variable: indexedDB openDB index.js: 15:30 blah blah blah

Does anyone know why this might be happening?

Thanks!

jakearchibald commented 5 years ago

I'm not really familiar with React Native. Are you running this code in a browser?

billtlee commented 5 years ago

The code is running on iOS.

billtlee commented 5 years ago

It appears that react-native does not support indexeddb yet. Hopefully it will soon.

jakearchibald commented 5 years ago

Yeah, this is a wrapper library, so it needs to run in an environment that has indexeddb.