Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Sveltekit Reference Error window is not defined #269

Closed
laxadev opened this issue Mar 3, 2023 · 7 comments
Closed

Sveltekit Reference Error window is not defined #269

laxadev opened this issue Mar 3, 2023 · 7 comments
Assignees
Labels
bug Something isn't working triaged Issue has been looked at and triaged

Comments

@laxadev
Copy link

laxadev commented Mar 3, 2023

I'm using SvelteKit and since I moved to version 5.8.0 from 5.7.5 the site throws this error when I hard refresh the site.

ReferenceError: window is not defined File "/Projects/sveltekit-sk/node_modules/picmo/dist/index.js", line 287, in <anonymous> '{snip} le.warn("[picmo] sessionStorage not available, falling back to simple in-memory storage"), Object.defineProperty(window, "sessionStorage", { File "node:internal/modules/esm/module_job", line 194, in ModuleJob.run

It is working perfectly fine with version 5.7.5 but with the latest or with 5.7.6 I get this.

@joeattardi
Copy link
Owner

Oops! I added some checks for local storage, looks like I missed the case when running on the server (the check involves accessing the window object). This should be an easy fix. Thanks for reporting!

@joeattardi joeattardi self-assigned this Mar 4, 2023
@joeattardi joeattardi added bug Something isn't working triaged Issue has been looked at and triaged labels Mar 4, 2023
@joeattardi
Copy link
Owner

Not sure if you can share your code but I created a quick test SvelteKit project and as long as I create the picker in onMount in a component, the picker is created and I don't see the error.

Can you share some code showing how you're using the picker in a SvelteKit app so I can try to recreate it and add the proper check?

@laxadev
Copy link
Author

laxadev commented Mar 4, 2023

In dev mode everything is fine.
I've just created a quick example here. https://github.com/laxadev/sk-picmo
After you clone it run npm run build and after that run it in preview mode npm run preview

@joeattardi
Copy link
Owner

Ah, I only tried it in development mode! Sorry, I am not super familiar with SvelteKit.

I think I've got it, after I run build and preview the picker works now without error. Should have a new release ready shortly.

@joeattardi
Copy link
Owner

Ok! Just published 5.8.1. Let me know if that solves the issue! Thanks for providing that test case.

@laxadev
Copy link
Author

laxadev commented Mar 4, 2023

Everything is working. Thank you for your quick fix.

@joeattardi
Copy link
Owner

Awesome, again sorry about that. Thanks for using the library!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working triaged Issue has been looked at and triaged
Projects
None yet
Development

No branches or pull requests

3 participants
@joeattardi @laxadev and others