dexie / Dexie.js

A Minimalistic Wrapper for IndexedDB
https://dexie.org
Apache License 2.0
11.69k stars 641 forks source link

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

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

Any clue?

aguycalled commented 2 years ago
% node --version
v15.14.0
% npm --version
7.7.6

Dexie version: 3.2.0 indexedDBshim version: 8.0.0

aguycalled commented 2 years ago
      console.log(window.indexedDB);

      this.db = new Dexie(filename);

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
dfahlander commented 2 years ago

Seems odd. Maybe a race condition as one module is using top level await and might resolve after Dexie is instantiated. If you have the time, a repro would help for debugging it.

aguycalled commented 2 years ago

refactored the code and now it's working, seemed to be related to a race condition. closing