localForage icon indicating copy to clipboard operation
localForage copied to clipboard

TypeError: t.ready is not a function

Open lovasoa opened this issue 4 years ago • 8 comments

After a recent update, localforage started throwing the following error:

Uncaught (in promise) TypeError: t.ready is not a function

I use localforage as an asynchronous module, required dynamically with import().

image

The project's sources are here: https://github.com/lovasoa/sanipasse/

lovasoa avatar Sep 24 '21 22:09 lovasoa

Sounds like you are doing something like:

const setItem = localForage.setItem;
setItem('something', 'something');

Can you provide a stacktrace from the non-minified sources so that we can understand more of what might be happening?

thgreasi avatar Sep 26 '21 22:09 thgreasi

Hello !

The problem does not occur in development. It only happens after bundling (with sveltekit, that uses esbuild).

I am working around it by replacing import("localforage") by import("localforage").then(x => x.default)

https://github.com/lovasoa/sanipasse/blob/master/src/lib/storage.ts#L1-L5

lovasoa avatar Sep 27 '21 08:09 lovasoa

Can you try reproducing after enabling sourcemaps on your production build? I'm not sure whether the async module import might be the issue here, since we are using UMD exports. Can you paste here what import("localforage") returns for you and whether after it returns whether window.localforage holds any value?

Does the issue happen if you use a normal ES6 import from statement?

thgreasi avatar Sep 27 '21 09:09 thgreasi

I cannot use a simple import from in my project, because the code has to run on both node and the browser. In node, just importing localforage throws an error, without even using it at all.

I worked around the problem in my project, and I just wanted to report the bug upstream. I don't really have the time to run more experiments on this. If you want, you can reproduce the error on this commit: https://github.com/lovasoa/sanipasse/tree/f0887468f069cc682f4c3c9a1fea4bff7156f5da

lovasoa avatar Sep 27 '21 12:09 lovasoa

index-40421e02.js:40  TypeError: l.ready is not a function
    at index-40421e02.js:6:10350
    at new Promise (<anonymous>)
    at Module._s (index-40421e02.js:6:10328)
    at Mn.storagePages (index-40421e02.js:40:47866)
    at index-40421e02.js:40:75639
    at Zh (index-40421e02.js:40:73781)
    at xo (index-40421e02.js:40:73857)

import * as localforage from "localforage";

localforage.config({
    driver: localforage.INDEXEDDB, // Force IndexedDB; same as using setDriver()
    name: 'showDataDb',
    storeName: 'showDataStore',
});
export default localforage;

JavaScriptNinja01 avatar Aug 28 '23 03:08 JavaScriptNinja01

index-40421e02.js:40  TypeError: l.ready is not a function
    at index-40421e02.js:6:10350
    at new Promise (<anonymous>)
    at Module._s (index-40421e02.js:6:10328)
    at Mn.storagePages (index-40421e02.js:40:47866)
    at index-40421e02.js:40:75639
    at Zh (index-40421e02.js:40:73781)
    at xo (index-40421e02.js:40:73857)
import * as localforage from "localforage";

localforage.config({
    driver: localforage.INDEXEDDB, // Force IndexedDB; same as using setDriver()
    name: 'showDataDb',
    storeName: 'showDataStore',
});
export default localforage;

我也是这么写的

cuijiudai avatar Dec 15 '23 04:12 cuijiudai