{"record":{"id":"4d5556dc68ca3a2e","repo":"parcel-bundler/parcel","slug":"idbcache-is-only-supported-in-the-browser","errorCode":null,"errorMessage":"IDBCache is only supported in the browser","messagePattern":"IDBCache is only supported in the browser","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/cache/src/IDBCache.js","lineNumber":7,"sourceCode":"// @flow strict-local\nimport type {Cache} from './types';\n\n// $FlowFixMe\nexport class IDBCache implements Cache {\n  constructor() {\n    throw new Error('IDBCache is only supported in the browser');\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":10,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/cache/src/IDBCache.js#L1-L10","documentation":"IDBCache is a Cache implementation backed by IndexedDB, which exists only in browsers. The constructor throws immediately so the failure surfaces at instantiation rather than silently corrupting in Node. This class is only meant to be constructed in a browser runtime; importing the module in Node is fine, but constructing it is not.","triggerScenarios":"Calling `new IDBCache()` (or passing it as `options.cache`) in Node.js, jsdom, SSR, or any runtime without a real IndexedDB implementation.","commonSituations":"Sharing cache code between browser and server bundles; running unit tests under Node; server-side rendering that imports browser-only modules.","solutions":["Only instantiate IDBCache inside code that runs in the browser (guard with `typeof indexedDB !== 'undefined'`).","Use the default filesystem cache (or another Node-compatible Cache) on the server.","Dynamically import IDBCache from a browser-only entry point so it never loads in Node."],"exampleFix":"// before\nimport {IDBCache} from '@parcel/cache';\nconst cache = new IDBCache();\n\n// after\nimport {FSCache} from '@parcel/cache';\nconst cache = typeof indexedDB !== 'undefined'\n  ? new (await import('@parcel/cache')).IDBCache()\n  : new FSCache(cacheDir);","handlingStrategy":"type-guard","validationCode":"// Before constructing, confirm a browser IndexedDB is present.\nconst hasIDB = typeof indexedDB !== 'undefined' && indexedDB !== null;\nconst cache = hasIDB ? new IDBCache() : fallbackNodeCache();","typeGuard":"function isBrowserWithIDB(): boolean {\n  return typeof indexedDB !== 'undefined' && indexedDB !== null;\n}","tryCatchPattern":null,"preventionTips":["Keep IDBCache imports in browser-only entry points.","In SSR/tests, default to the filesystem cache.","Add a feature-detect helper and reuse it wherever caches are constructed."],"tags":["browser","cache","indexeddb","environment"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}