{"id":655,"hash":"1f202d9395aa7a942bf6821d835e386f2c590b34698e0f7fdda05c357a3c0d7f","pattern":"Jest SecurityError: localStorage is not available for opaque origins","full_message":"When I want to run my project with the command npm run test, I get the error below. What is causing this?\n\nFAIL\n● Test suite failed to run\n\nSecurityError: localStorage is not available for opaque origins at Window.get localStorage [as localStorage] (node_modules/jsdom/lib/jsdom/browser/Window.js:257:15)\n      at Array.forEach (<anonymous>)","ecosystem":"npm","package_name":"node.js","package_version":null,"solution":"In case, if you are accessing your application with a http://localhost prefix, you need to update your jest configuration (in your jest.config.js) as,\n\n  \"jest\": {\n    \"verbose\": true,\n    \"testURL\": \"http://localhost/\"\n  }\n\nIn case you do not already have any jest configuration, just include the configuration in your package.json. For example:\n\n{\n  \"name\": \"...\",\n  \"description\": \"...\",\n  ...\n  \"jest\": {\n    \"verbose\": true,\n    \"testURL\": \"http://localhost/\"\n  }\n}\n\nor in jest.config.js :\n\nmodule.exports = {\n  verbose: true,\n  testURL: \"http://localhost/\",\n  ...\n}\n\nor if you have projects configured:\n\nmodule.exports = {\n  verbose: true,\n  \n  projects: [{\n    runner: 'jest-runner',\n    testURL: \"http://localhost/\",\n\n    // ...\n  }]\n}\n\nfor configuration in package.json, testURL is removed in jest v28. Now you should use testEnvironmentOptions to pass url option like that:\n\n\"jest\": {\n    \"verbose\": true,\n    \"testEnvironmentOptions\": {\n        \"url\": \"http://localhost/\"\n    }\n}","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/51554366/jest-securityerror-localstorage-is-not-available-for-opaque-origins","votes":175,"created_at":"2026-04-19T04:51:27.261642+00:00","updated_at":"2026-04-19T04:51:27.261642+00:00"}