brittneypostma / sveltekit-kanban

4 stars 1 forks source link

ReferenceError: localStorage is not defined #2

Open kasparpalgi opened 2 years ago

kasparpalgi commented 2 years ago

Hi Brittney, great YouTube video tutorial and board. Thanks. Any idea why I get this error?

localStorage is not defined
ReferenceError: localStorage is not defined
    at Module.persistStore (/src/stores/persistStore.js:4:19)
    at /src/stores/store.js:39:21
    at async instantiateModule (file:///C:/Git/svelte/sveltekit-kanban/node_modules/vite/dist/node/chunks/dep-db16f19c.js:53436:9)
brittneypostma commented 2 years ago

So, you converted this to use SvelteKit? I am assuming it is because it is trying to run it on the server where localStorage doesn't exist. You would have to make sure the function is running on the client with SvelteKit. Can you share your repo or other code?

kasparpalgi commented 2 years ago

Thanks a lot, Britney for coming back. I'm travelling and working/studying a lot offline. Trying now an online and same issue. As it's using stores and local storage I don't think it's to do with an internet connection. Here's the fork: https://github.com/crewnew-git/sveltekit-kanban I had multiple other errors that you can see I got rid of with my commit.

you converted this to use SvelteKit

No, you had under your video two repos. Svelte and SvelteKit one. This repo was SvelteKit from the beginning. The other repo https://github.com/brittneypostma/svelte-kanban I tried, too as I didn't get this SvelteKit one working. The other once drag'n'drop doesn't just work. No errors. Just drag'n'drop doesn't work and I noticed also that sometimes when deleting one card from later added list it will instead delete a wrong card. But that one I feel more comfortable to debug. The drag'n'drop thing is something I'm excited to learn from here and want to build this Kanban board usable with Supabase or Hasura or some backend.

brittneypostma commented 2 years ago

Oh, I even forgot I did that 😅

Sveltekit has changed so much I wouldn't expect it to work. There is probably a way to run it, but you need to make sure it's available in the client side rather than running on the server. I don't know off the top of my head how to do that. I'll look into your repo.

brittneypostma commented 2 years ago

Pretty sure I'm right about loading the data. It needs to be in an onMount or if(browser) block, but I think the actual store files need to be rewritten and pulled into them as well. They can't access localStorage where they are being called currently.