Node 25 - Zustand persist blows up in node 25 #3266
Unanswered
Nick2bad4u
asked this question in
Bug report
Replies: 3 comments 5 replies
-
|
Thanks for reporting! What's your idea for the fix? |
Beta Was this translation helpful? Give feedback.
0 replies
-
I built my own custom web storage shim in the mean time to get my tests working. Works fine, but I'm not sure it'll work for everyone. I'm not super familiar with this codebase. |
Beta Was this translation helpful? Give feedback.
4 replies
-
|
tbh, that's a expected behavior for this case you need to create a custom storage or mock localStorage |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Bug Description
Zustand persist breaks with Node 25’s new web storage stub
Summary
Running stores wrapped in
persistnow explodes with:under Node.js 25 whenever the process receives
--localstorage-filewithout a valid path.Node 25 auto-initializes a bare
{}atglobalThis.localStoragein that configuration; the persist middleware trustslocalStorageblindly and callssetItem→ immediate crash.Environment
zustand/middleware→persist)nodeMinimal Repro
NODE_OPTIONScontains--localstorage-filewithout a path (VS Code’s JS debug bootloader does this automatically, but you can set it yourself).repro.mjs:Expected
If
getStorage()hands back something that doesn’t actually behave like Web Storage,persistshould notice. It should either fall back to an in-memory store or throw a specific, helpful error. The one thing it must not do is blindly call.setItem()on a value whose methods haven’t been verified.Actual
Under Node 25,
localStorageresolves to a plain{}.persistskips validation, calls.setItem, and the store crashes immediately. Any persisted store-tests, scripts, production-dies the moment it initializes.Why It Matters
The
--localstorage-fileflag is now common (VS Code’s debugger sets it automatically), so this configuration isn’t exotic. Without a fix, every Zustand project that upgrades to Node 25 hits a fatal error unless they add custom shims.Reproduction Link
I put one in the bug report
Beta Was this translation helpful? Give feedback.
All reactions