Skip to content

fix: Fix 500 error due to undefined storage#1939

Closed
danielh-official wants to merge 1 commit intosveltejs:mainfrom
danielh-official:1938-fix-500-error
Closed

fix: Fix 500 error due to undefined storage#1939
danielh-official wants to merge 1 commit intosveltejs:mainfrom
danielh-official:1938-fix-500-error

Conversation

@danielh-official
Copy link
Copy Markdown
Contributor

Issue: #1938

Because #storage can be undefined, calling getItem as a function throws an error.

I've wrapped it in a try...catch block to return the fallback on catch.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time.
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.

Issue: sveltejs#1938

Because #storage can be undefined, calling getItem as a function throws an error.

I've wrapped it in a try...catch block to return the fallback on catch.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 17, 2026

@danielh-official is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

@Conduitry
Copy link
Copy Markdown
Member

This doesn't sound right to me. If this.#storage were undefined, then this.#storage?.getItem(this.#key) would also be undefined, not throw an exception. The error you're getting in the linked issue sounds like this.#storage is not undefined, but it doesn't have a getItem method, and I don't know when that would happen.

@Conduitry
Copy link
Copy Markdown
Member

Ah. localStorage was added as a global in Node 25, without needing the --experimental-webstorage flag. (nodejs/node#57666) But it's non-functional if you don't start Node with --localstorage-file. I expect just doing this.#storage?.getItem?.(this.#key) should work in this case. We'd still get the warning from Node the first time about needing to specify a file, but I don't have a good idea about how to handle that off the top of my head other than to also just check whether we're on the server or in a browser.

@teemingc
Copy link
Copy Markdown
Member

closing in favour of #1941

@teemingc teemingc closed this Apr 17, 2026
@danielh-official danielh-official deleted the 1938-fix-500-error branch April 17, 2026 12:02
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

Successfully merging this pull request may close these issues.

Getting 500 error when trying to run locally

3 participants