DEV Community


Discussion on: πŸš€ Svelte Quick Tip: Connect a store to local storage

kenkunz profile image
Ken Kunz

I got the same error while migrating an app to SvelteKit. The FAQ states this is due to how Vite processes imports (even with SSR disabled). See "How do I use a client-side only…" in SvelteKit FAQ as well as Issue #754 True SPA mode.

For now, I was able to get this working by disabling SSR on the page that depends on localStorage and importing & globally registering node-localstorage before importing the lib that depends on localStorage.

import 'node-localstorage/register';
import { storable } from 'svelte-storable';
Enter fullscreen mode Exit fullscreen mode

The register endpoint in node-localstorage does not overwrite localStorage if it already exists, so you still get the native browser implementation.