Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trying to build on sveltekit; indexedDB is not defined #96

Open
codegod100 opened this issue Apr 25, 2022 · 8 comments
Open

trying to build on sveltekit; indexedDB is not defined #96

codegod100 opened this issue Apr 25, 2022 · 8 comments

Comments

@codegod100
Copy link

ReferenceError: indexedDB is not defined
    at /home/vera/global-agora/node_modules/.pnpm/@isomorphic-git+idb-keyval@3.3.2/node_modules/@isomorphic-git/idb-keyval/dist/idb-keyval-cjs.js:17:29
    at new Promise (<anonymous>)
    at Store._init (/home/vera/global-agora/node_modules/.pnpm/@isomorphic-git+idb-keyval@3.3.2/node_modules/@isomorphic-git/idb-keyval/dist/idb-keyval-cjs.js:16:21)
    at new Store (/home/vera/global-agora/node_modules/.pnpm/@isomorphic-git+idb-keyval@3.3.2/node_modules/@isomorphic-git/idb-keyval/dist/idb-keyval-cjs.js:10:14)
    at new IdbBackend (/home/vera/global-agora/node_modules/.pnpm/@isomorphic-git+lightning-fs@4.6.0/node_modules/@isomorphic-git/lightning-fs/src/IdbBackend.js:7:19)
    at DefaultBackend.init (/home/vera/global-agora/node_modules/.pnpm/@isomorphic-git+lightning-fs@4.6.0/node_modules/@isomorphic-git/lightning-fs/src/DefaultBackend.js:30:23)
    at PromisifiedFS._init (/home/vera/global-agora/node_modules/.pnpm/@isomorphic-git+lightning-fs@4.6.0/node_modules/@isomorphic-git/lightning-fs/src/PromisifiedFS.js:84:27)
 ELIFECYCLE  Command failed with exit code 1.
@jcubic
Copy link
Contributor

jcubic commented Apr 25, 2022

Ok, nice that you have stack trace but this doesn't say anything. Can you at least show the code that generated that error? And what kind of environment do you have?

@josh-sachs-epic
Copy link

Having the same issue... Obviously indexedDB doesn't exist on node backend... Store._init is attempting access despite running on node and not the browser.

Is this actually isomorphic, or am I missing something?

@jcubic
Copy link
Contributor

jcubic commented May 22, 2022

@josh-sachs-epic why would you want to use the browser library in Node? LightingFS is a replacement for the node fs module for the browser. Can you just use the node fs module?

@josh-sachs-epic
Copy link

Sure - I want to use FS on node and LightningFS in the browser. Its just that, based on the description, I expected that this lib abstracted that away for me (running the correct bits in node / browser).

I was chiming in on this thread b/c you commented that the submitter's stack trace didn't reveal anything, when in fact it does. They are also assuming the library can handle running in both environments, when it cannot (which is fine - just ambiguity around the use of the term 'isomorphic').

@jcubic
Copy link
Contributor

jcubic commented May 23, 2022

It's not isomorphic-fs it's a library that can be used in isomorphic-git in the browser.

@ninjadev64
Copy link

Solution is just to initialise FS in onMount.

@jcubic
Copy link
Contributor

jcubic commented Oct 27, 2023

@ninjadev64 this will not help, the problem is that the OP has problem with using lightning-fs that was created for Browser outside of the Browser context.

@ninjadev64
Copy link

@ninjadev64 this will not help, the problem is that the OP has problem with using lightning-fs that was created for Browser outside of the Browser context.

I'm using it in the same environment as them and had the same issue. SvelteKit pre-renders and pre-executes Svelte files and JS code in them, both in dev and in deployment. This allows it to send a fully rendered HTML file to the client so that the client doesn't have to wait for it to hydrate on their end.

However, in this process, globals like document and window, as well as browser only technologies like indexedDB, are unavailable. onMount allows the developer to specify a function that is only run when the page is loaded in the browser and these globals have become available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants