indexeddbshim / IndexedDBShim

A polyfill for IndexedDB using WebSql
Other
968 stars 191 forks source link

Can't use Dexie with indexedDBshim from ESM module #362

Closed aguycalled closed 2 years ago

aguycalled commented 2 years ago

Trying

const setGlobalVars = (await import("indexeddbshim")).default;

global.window = global;
setGlobalVars();

Gives me this error:

DatabaseClosed error: MissingAPIError IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb
% node --version
v15.14.0
% npm --version
7.7.6

Dexie version: 3.2.0 indexedDBshim version: 8.0.0

Any clue?

brettz9 commented 2 years ago

Have you introspected to see whether you are getting a global indexedDB object after setGlobalVars and before your use of Dexie?

aguycalled commented 2 years ago
const setGlobalVars = (await import("indexeddbshim")).default;

global.window = global;
setGlobalVars(global, { checkOrigin: false });
if (!window.indexedDB) {
  console.log("No indexedDB!");
} else {
  console.log(window.indexedDB);
}

outputs:

IDBFactory {
  __connections: {},
  __useShim: [Function (anonymous)],
  __debug: [Function (anonymous)],
  __setConfig: [Function: setConfig],
  __getConfig: [Function (anonymous)],
  __setUnicodeIdentifiers: [Function (anonymous)],
  __openDatabase: [Function: bound ],
  [Symbol(Symbol.toStringTag)]: 'IDBFactory'
}
DatabaseClosed error: MissingAPIError IndexedDB API missing. Please visit https://tinyurl.com/y2uuvskb
brettz9 commented 2 years ago

Ok, well, it looks fine on our end. It sounds your loading of this file may not be loading in time for Dexie. I think you'll want to raise this question over there (or on a support site like Stackoverflow). Closing as that should resolve, but feel free to comment further if really needed.