jakearchibald / idb

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

Unable to open indexedDB using idb library (error thrown with no message) #243

Closed juicetin closed 2 years ago

juicetin commented 2 years ago

Hi,

Please see here (https://jsfiddle.net/adestic/gs13fpbk/) for a minimal reproducible case using sample code where I'm just trying to open the DB. The error thrown happens at the openDB statement before any other operations happen. In each test, I've confirmed vanilla use of the window.indexedDB object can open and transact against indexedDB without issues.

Expected: able to open indexedDB using idb Observed: the open operation throws an error without any error message

Tested on: OS: Arch Linux 5.14.16arch-1 Browsers:

jakearchibald commented 2 years ago

See the error it produces:

ReferenceError: openDB is not defined

That should give you a clue 😄

From the README:

Using external script reference

<script src="https://unpkg.com/idb/build/iife/index-min.js"></script>
<script>
  async function doDatabaseStuff() {
    const db = await idb.openDB(…);
  }
</script>

A global, idb, will be created, containing all exports of the module version.

Whereas your code is not using the idb global. Either use the idb global, or destructure it:

const { openDB } = idb;
juicetin commented 2 years ago

@jakearchibald apologies! 100%, I posted a JS fiddle with an unrelated and silly bug instead of what I'm actually running into inside a slightly more complex codebase and jumped to post it when I thought I reproduce the same bug. I'll open a new ticket if I can reproduce the actual bug.