{"record":{"id":"7126438649ec8f4d","repo":"nodejs/node","slug":"memorycachestore-options-must-be-an-object","errorCode":null,"errorMessage":"MemoryCacheStore options must be an object","messagePattern":"MemoryCacheStore options must be an object","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"deps/undici/src/lib/cache/memory-cache-store.js","lineNumber":35,"sourceCode":" */\nclass MemoryCacheStore extends EventEmitter {\n  #maxCount = 1024\n  #maxSize = 104857600 // 100MB\n  #maxEntrySize = 5242880 // 5MB\n\n  #size = 0\n  #count = 0\n  #entries = new Map()\n  #hasEmittedMaxSizeEvent = false\n\n  /**\n   * @param {import('../../types/cache-interceptor.d.ts').default.MemoryCacheStoreOpts | undefined} [opts]\n   */\n  constructor (opts) {\n    super()\n    if (opts) {\n      if (typeof opts !== 'object') {\n        throw new TypeError('MemoryCacheStore options must be an object')\n      }\n\n      if (opts.maxCount !== undefined) {\n        if (\n          typeof opts.maxCount !== 'number' ||\n          !Number.isInteger(opts.maxCount) ||\n          opts.maxCount < 0\n        ) {\n          throw new TypeError('MemoryCacheStore options.maxCount must be a non-negative integer')\n        }\n        this.#maxCount = opts.maxCount\n      }\n\n      if (opts.maxSize !== undefined) {\n        if (\n          typeof opts.maxSize !== 'number' ||\n          !Number.isInteger(opts.maxSize) ||\n          opts.maxSize < 0","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/undici/src/lib/cache/memory-cache-store.js#L17-L53","documentation":"Thrown by the MemoryCacheStore constructor (undici's in-memory HTTP cache backing store) when opts is provided but typeof opts !== 'object'. The store is used by the CacheInterceptor to cache responses in process memory. Passing a string, number, array, or other non-object triggers this before any field validation.","triggerScenarios":"Constructing new MemoryCacheStore('100') or new MemoryCacheStore(100) by mistake; passing a JSON string instead of a parsed object; passing an array of config entries.","commonSituations":"Reading cache config from an env var or file as a string and forgetting JSON.parse; passing the wrong variable (a size number instead of an opts object); copy-paste from an example that omitted the braces.","solutions":["Pass a plain object (or omit for defaults): new MemoryCacheStore({ maxCount: 1000, maxSize: 1e8 }).","If config comes from JSON text, parse it first: JSON.parse(cfgStr).","If you only need defaults, call new MemoryCacheStore() with no argument."],"exampleFix":"// before\nnew MemoryCacheStore(configStr) // string from env\n\n// after\nnew MemoryCacheStore(JSON.parse(configStr))\n// or simply\nnew MemoryCacheStore({ maxCount: 1000 })","handlingStrategy":"validation","validationCode":"function makeCacheStore(opts) {\n  if (opts == null) return new MemoryCacheStore()\n  if (typeof opts === 'string') opts = JSON.parse(opts)\n  if (!opts || typeof opts !== 'object' || Array.isArray(opts)) {\n    throw new TypeError('MemoryCacheStore options must be an object')\n  }\n  return new MemoryCacheStore(opts)\n}","typeGuard":"function isStoreOpts(v) { return !!v && typeof v === 'object' && !Array.isArray(v) }","tryCatchPattern":null,"preventionTips":["Always pass a plain object (or nothing) to the MemoryCacheStore constructor.","JSON.parse config strings before passing them in.","Use a factory helper that validates the shape once."],"tags":["undici","cache","memory-cache-store","validation","configuration"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}