Skip to content

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

Open

Description

@codegod100
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.

Activity

  1. jcubic commented on Apr 25, 2022

    @jcubic
    Member

    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?

  2. josh-sachs-epic commented on May 22, 2022

    @josh-sachs-epic

    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?

  3. jcubic commented on May 22, 2022

    @jcubic
    Member

    @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?

  4. josh-sachs-epic commented on May 23, 2022

    @josh-sachs-epic

    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').

  5. jcubic commented on May 23, 2022

    @jcubic
    Member

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

  6. nekename commented on Oct 27, 2023

    @nekename

    Solution is just to initialise FS in onMount.

  7. jcubic commented on Oct 27, 2023

    @jcubic
    Member

    @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.

  8. nekename commented on Oct 27, 2023

    @nekename

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions