[Unhandled promise rejection: ReferenceError: Can't find variable: indexedDB] at node_modules/idb-keyval/dist/compat.cjs:34:12 in createStore
carlnx opened this issue · comments
Well... now another issue that I did not understand :(
When I use parse (see code), it happens the error:
[Unhandled promise rejection: ReferenceError: Can't find variable: indexedDB]
at node_modules/idb-keyval/dist/compat.cjs:34:12 in createStore
The code that calls this error:
import AsyncStorage from '@react-native-async-storage/async-storage';
const bdParse = () => {
const Parse = require('parse/react-native.js');
Parse.setAsyncStorage(AsyncStorage);
//APP_ID
Parse.initialize('xxxxxxxxxx');
Parse.masterKey = 'xxxxxxxxx';
Parse.serverURL = 'https://xxxx.xzxxx.xxx.xx.xx/parse';
return Parse;
}
Any ideas? :(
Originally posted by @carlnx in #144 (comment)
This isn't enough of an example for me to debug this. Eg, the "code that calls this error" doesn't reference idb-keyval at all, so I have no idea how it's called or loaded.
I suspect it's being run in a non-browser environment, but I'm just guessing.
Please create a minimal reproducible example (https://stackoverflow.com/help/minimal-reproducible-example). Ideally, the example should be accessible somewhere public, like jsbin, Glitch, jsfiddle, codepen etc etc.
I'll reopen this issue once the details are provided.
@carlnx @jakearchibald I have got the same issue and I've added a minimal example below.
https://github.com/chillaxdev/RNIDbIssue
Thank You.
Does React Native run in a browser context? What origin does it run code in? As in, what's window.origin
?
Same error here. Have you found a solution?
@tiavina-mika can you answer my question above? #145 (comment)
@jakearchibald , I'm not @tiavina-mika , but my code runs in React Native with Expo configured for Android and iOS, without web. I do not know if it helps you.
idb-keyval has a hard dependency on IndexedDB
, which is a web API. It won't run in a non-web context unless you're polyfilling web APIs.
@jakearchibald how to achieve that? I'm in a React Native (IOS, Android) project
I need someone to answer the following questions:
- When you see the error, is the code running in the context of a web browser or web view? If you don't know what that means, it would be useful to know the result of
console.log(typeof self)
andconsole.log(typeof self.indexedDB)
. - If the code is running in the context of a web browser or web view, what's the value of
self.origin
. As in, what is logged viaconsole.log(self.origin)
?
@jakearchibald here is the values of self:
{
"process": {
"env": {
"NODE_ENV": "development"
}
},
"__DEV__": true,
"__BUNDLE_START_TIME__": 42465743.3403,
"__jsiExecutorDescription": "<JSCRuntime@0xae4a42b0>",
"nativeFlushQueueImmediate": [Function nativeFlushQueueImmediate],
"nativeCallSyncHook": [Function nativeCallSyncHook],
"nativeLoggingHook": [Function nativeLoggingHook],
"nativePerformanceNow": [Function nativePerformanceNow],
"__r": [Function metroRequire],
"__d": [Function define],
"__c": [Function clear],
"__registerSegment": [Function registerSegment],
"$RefreshReg$": [Function anonymous],
"$RefreshSig$": [Function anonymous],
"__accept": [Function metroHotUpdateModule],
"ErrorUtils": {
"applyWithGuard": [Function applyWithGuard],
"applyWithGuardIfNeeded": [Function applyWithGuardIfNeeded],
"getGlobalHandler": [Function getGlobalHandler],
"guard": [Function guard],
"inGuard": [Function inGuard],
"reportError": [Function reportError],
"reportFatalError": [Function reportFatalError],
"setGlobalHandler": [Function setGlobalHandler],
},
"GLOBAL": [Object],
"window": [Object],
"self": [Object],
"performance": {
"now": [Function anonymous],
},
"__fbGenNativeModule": [Function genModule],
"originalRegeneratorRuntime": {
"AsyncIterator": [Function AsyncIterator],
"async": [Function anonymous],
"awrap": [Function anonymous],
"isGeneratorFunction": [Function anonymous],
"keys": [Function anonymous],
"mark": [Function anonymous],
"values": [Function values],
"wrap": [Function wrap],
},
"alert": [Function anonymous],
"navigator": {
"geolocation": {
"clearWatch": [Function clearWatch],
"getCurrentPosition": [Function anonymous],
"stopObserving": [Function stopObserving],
"watchPosition": [Function anonymous],
},
"product": "ReactNative",
},
"__fetchSegment": [Function __fetchSegment],
"__getSegment": [Function __getSegment],
"setTimeout": [Function setTimeout],
"clearTimeout": [Function clearTimeout],
"setImmediate": [Function setImmediate],
"clearImmediate": [Function clearImmediate],
"Intl": {
"PluralRules": [Function PluralRules],
},
"Blob": [Function Blob],
"Headers": [Function Headers],
"Request": [Function Request],
"Response": [Function Response],
"fetch": [Function fetch],
"__reanimatedWorkletInit": [Function anonymous],
"_setGlobalConsole": [Function anonymous],
"_WORKLET": false,
"_log": [Function anonymous],
"XMLHttpRequest": [Function XMLHttpRequest],
"WebSocket": [Function WebSocket],
"Buffer": [Function Buffer],
"__blobCollectorProvider": [Function __blobCollectorProvider],
"URLSearchParams": [Function URLSearchParams],
"FileReader": [Function FileReader],
"regeneratorRuntime": {
"AsyncIterator": [Function AsyncIterator],
"async": [Function anonymous],
"awrap": [Function anonymous],
"isGeneratorFunction": [Function anonymous],
"keys": [Function anonymous],
"mark": [Function anonymous],
"values": [Function values],
"wrap": [Function wrap],
},
"setInterval": [Function setInterval],
"clearInterval": [Function clearInterval],
"requestAnimationFrame": [Function requestAnimationFrame],
"cancelAnimationFrame": [Function cancelAnimationFrame],
"requestIdleCallback": [Function requestIdleCallback],
"cancelIdleCallback": [Function cancelIdleCallback],
"FormData": [Function FormData],
"File": [Function File],
"URL": [Function URL],
"AbortController": [Function AbortController],
"AbortSignal": [Function AbortSignal],
}
console.log(typeof self.indexedDB)
and console.log(self.origin)
return undefined
console.log(typeof self.indexedDB)
andconsole.log(self.origin)
returnundefined
That's what I needed.
idb-keyval
is a library built on top of the web standard storage IndexedDB
(that's why it's called idb-keyval
). As such, this is a library intended to run in an environment that sufficiently implements IndexedDB
, such as a browser.
React native is not a web-compatible environment, so this library will not work.
I'm not a React native developer, so I can't recommend an alternative storage library for you. React native's docs suggest looking at https://reactnative.directory/?search=storage. I have no idea if any of those work.