[Bug]: Jest fails with localstorage error with node 25.2.0
Version
30.2.0
Steps to reproduce
Reproduction steps:
- Clone https://github.com/shadowspawn/jest-local-storage
- using node 25.2.0...
- npm install
- npx jest
Expected behavior
I expect the tests to run and pass.
Actual behavior
% npx jest
FAIL ./index.test.js
ā Test suite failed to run
SecurityError: Cannot initialize local storage without a `--localstorage-file` path
at new NodeEnvironment (node_modules/jest-environment-node/build/index.js:110:52)
Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.029 s
Ran all test suites.
Additional context
I am using testEnvironment: "node".
There was a change of behaviour in https://github.com/nodejs/node/pull/60351
This failed the node CITGM test for Commander: https://github.com/nodejs/node/pull/60677#issuecomment-3518940754
After reproducing, I opened an issue for Commander: https://github.com/tj/commander.js/issues/2451
And then added a reproduction here!
Environment
System:
OS: macOS 26.1
CPU: (10) arm64 Apple M1 Pro
Binaries:
Node: 25.2.0 - /usr/local/bin/node
npm: 11.6.2 - /usr/local/bin/npm
bun: 1.2.1 - /opt/homebrew/bin/bun
Deno: 2.1.7 - /opt/homebrew/bin/deno
npmPackages:
jest: ^30.2.0 => 30.2.0
i fixed it by:
npm install --save-dev jest-environment-jsdom- adding to jest.config.ts:
testEnvironment: "jsdom",
(In my case, I am testing in node environment. I will add that to the context in description, thanks.)
From the original PR's thread, I can see that the introduced feature/issue is still experimental and not really meant for stable userland. Having said that, one folk did say this one is worthy of semver-major so there's that.
There could be further modifications to this one in Node.js runtime so I'm not sure what's to put out as a guardrail, might be a try-catch when accessing globalThis attribute?
This solved it for me: I set the localStorage file path via NODE_OPTIONS like this:
NODE_OPTIONS='--localstorage-file=./jest-storage' jest
Update: For me this issue started because we were using "latest" as version for node in the pipelines. This caused node version 25.2.0 to be used, which ultimately caused the issue. That error throwing was added here #60351
Reported to Node.js - https://github.com/nodejs/node/issues/60704, this is a breaking change
Wonderful š
It is fixed in node v25.2.1
We'll still need to fix it tho, as it'll be in v26
Or it might be fixed upstream, let's see how https://github.com/nodejs/node/issues/60303 shakes out
Iād be happy to take this one on and prepare a fix @SimenB could you please assign me to this issue?
Thanks!