You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The probject experiences strange issues with Node 25. The testing environment throws an assertion and when using happy-dom as a testing environment the localStorage is an empty object.
To Reproduce
Steps to reproduce the behavior in relationship to the project itself:
Install and use Node 25 (nvm can be handy)
Clone the repo
npm install
npm run test
Expected behavior
Tests run and pass. This works flawlessly with Node 24.
Screenshots
To Reproduce (2)
Steps to reproduce the (probably related) issue about localStorage from an external project:
Install and use Node 25
Create a dummy project installing vitest and happy-dom
Expected behavior
Tests run and pass, works with Node 24
Screenshots
Device:
OS: Arch Linux
Node 25.1.0
Additional context
I cannot be sure the two noticed behavior are directly correlated, I only supposed so. If you realize the two problems are separated issues just let me know and I will split this specific issue in two.
I enjoyed the fact that localstorage used to "just work" under Happy DOM. If necessary, I will use Vitest's execArgv config option to pass --localstorage-file into my test suite, but ideally Happy DOM could do this for me on Node 25+.
I just found vitest-dev/vitest#8757 , who is punting the issue to upstream Node (which I think is appropriate, though maybe Happy DOM is responsible too).
In Node, it looks like v25.2 (released yesterday) contains a fix for nodejs/node#60303 . I just installed v25.2.0 and any access to localstorage now immediately fails with:
SecurityError: Cannot initialize local storage without a --localstorage-file path
This error is also now occurring call to window.localStorage.clear() (which previously didn't fail on v25.1).
Perhaps Happy DOM can do this, and polyfill window.localstorage with its existing implementation if Node isn't providing it (either because it's not implemented in < v25 or because it's not configured via --localstorage-file).
If we want to get Node v25.0 and v25.1 working, an additional check might be necessary.
I will be so happy when this is fixed, been dealing with dozens of these warnings being spammed in the console since November. I'm getting this when testing Vue components that get/set localStorage (dark mode setting, etc), when testing them in Vitest/Vue-Dev-Tools/HappyDOM. Example:
test('Loads light value from local storage',async()=>{window.localStorage.setItem(localStorageId,'{"theme":"light"}');constwrapper=awaitsetupWrapper();expect(wrapper.vm.loadData()).toEqual({theme: 'light'});});
Not sure if this needs fixed at the Node, Vitest, or HappyDOM level, but excited to see it fixed somewhere so the work-around won't be needed.
Reacted by Johannes Ewald, Michal Szajter, Rafał Goławski, Martin Novák, Anastasia Sharubina, Nuno Balbona, Alexander Brown, Ilia Burakov and The Jared Wilcurt
Reacted by The Jared Wilcurt, Nuno Balbona and Alexander Brown
For anyone still hitting this on Node 25+ with vitest: it was fixed in vitest 5.0.0 (vitest-dev/vitest#10293). The fix wasn't backported to v4, so upgrading to vitest 5 should resolve it. I think this issue can be closed.
Activity
brianhelba commentedon Nov 12, 2025
I'm having the same issue.
Note, a warning is also being printed prior to the
localStorage.getItem is not a functionerror:There's a significant change in Node 25:
Looking at the Node docs, it appears that
localstorageis now available, but requires the--localstorage-fileflag. I'm guessing that Node'slocalstorageimplementation is now taking precedence over Happy DOM's polyfill.I enjoyed the fact that
localstorageused to "just work" under Happy DOM. If necessary, I will use Vitest'sexecArgvconfig option to pass--localstorage-fileinto my test suite, but ideally Happy DOM could do this for me on Node 25+.brianhelba commentedon Nov 12, 2025
I just found vitest-dev/vitest#8757 , who is punting the issue to upstream Node (which I think is appropriate, though maybe Happy DOM is responsible too).
In Node, it looks like v25.2 (released yesterday) contains a fix for nodejs/node#60303 . I just installed v25.2.0 and any access to
localstoragenow immediately fails with:This error is also now occurring call to
window.localStorage.clear()(which previously didn't fail on v25.1).Per the patch in Node nodejs/node#60351 (comment), it looks like for v25.2+, a downstream needs
Perhaps Happy DOM can do this, and polyfill
window.localstoragewith its existing implementation if Node isn't providing it (either because it's not implemented in < v25 or because it's not configured via--localstorage-file).If we want to get Node v25.0 and v25.1 working, an additional check might be necessary.
brianhelba commentedon Nov 12, 2025
As a workaround for now, I added to my
vitest.config.ts(using Vitest v4):My tests are passing again.
fix: [capricorn86#1950] Handle throwing localStorage getter for Node …
fix: [capricorn86#1950] Handle throwing localStorage getter for Node …
fix: [capricorn86#1950] Handle throwing localStorage getter for Node …
fix: [capricorn86#1950] Handle throwing localStorage getter for Node …
TheJaredWilcurt commentedon Feb 10, 2026
I will be so happy when this is fixed, been dealing with dozens of these warnings being spammed in the console since November. I'm getting this when testing Vue components that get/set localStorage (dark mode setting, etc), when testing them in Vitest/Vue-Dev-Tools/HappyDOM. Example:
Not sure if this needs fixed at the Node, Vitest, or HappyDOM level, but excited to see it fixed somewhere so the work-around won't be needed.
r-thomson commentedon Feb 10, 2026
Just wanted to share the workaround I have been using with Vitest:
Hopefully this is helpful to someone.
silverwind commentedon May 7, 2026
Node 26 is now stable, a lot more people will start hitting this.
disable node webstorage in frontend env on node 25+
fix: disable Node 25+ Web Storage API in vitest
fix: make the Node 26 move green
fix(create): disable native web storage in the generated vitest config
fix(create): disable native web storage in the generated vitest config
fix(create): disable native web storage in the generated vitest config
TrevorBurnham commentedon Oct 17, 2026
For anyone still hitting this on Node 25+ with vitest: it was fixed in vitest 5.0.0 (vitest-dev/vitest#10293). The fix wasn't backported to v4, so upgrading to vitest 5 should resolve it. I think this issue can be closed.