-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Describe the bug
In Node v25.0.0 released one week ago the Web Storage API is enabled by default (nodejs/node@3312e4e946 , nodejs/node#57666), of which the behavior is however different with the browser. Now localStorage in Node is no longer undefined. Test units with Vitest with either jsdom or happy-dom environment will fail to provide methods like localStorage.getItem. I'm not completely sure it's a bug from Vitest, but I guess it's some downstream software detects its existence and gives up mocking it up. With limited exploration I find jsdom has consistent behavior in Node v25 and Node v24, so I first post it here.
A workaround for people encountering the same error: Set an environment variable to disable Web Storage API: export NODE_OPTIONS="--no-webstorage".
Reproduction
I created a minimal reproduction here:
package.json
{
"name": "node25-vitest",
"version": "1.0.0",
"description": "",
"scripts": {
"test": "vitest"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"devDependencies": {
"jsdom": "^27.0.1",
"vitest": "^3.2.4"
}
}vitest.config.ts
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
environment: 'jsdom',
},
});demo.test.ts
import { describe, expect, it } from 'vitest';
describe('localStorage demo', () => {
it('foo', () => {
expect(typeof localStorage.getItem).toEqual('function');
});
});docker-compose.yml
services:
test-25:
image: node:25
volumes:
- ./:/app
command: "sh -c 'node --version && cd /app && npm install && npm test'"
test-24:
image: node:24
volumes:
- ./:/app
command: "sh -c 'node --version && cd /app && npm install && npm test'"package-lock.json
Ignored because it's too long. Generated at `2025-10-22 03:51:01.777312593 +0200`.The demo.test.ts will fail with Node v25 and succeed with Node v24. The docker compose file might help if you already have such environment.
System Info
vitest/3.2.4. Any system with Nodejs v25.0.0Used Package Manager
npm
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.