nodejs/node · error · TypeError
SqliteCacheStore options must be an object
Error message
SqliteCacheStore options must be an object
What it means
Thrown by the SqliteCacheStore constructor when opts is truthy but not an object (e.g. a string, number, array-without-intent, or a primitive wrapper). The constructor only branches into object validation when opts is truthy, then immediately asserts typeof === 'object'; passing a non-object primitive triggers this. Null is allowed (no opts) because the outer guard is `if (opts)`.
Source
Thrown at deps/undici/src/lib/cache/sqlite-cache-store.js:81
#deleteByUrlQuery
/**
* @type {import('node:sqlite').StatementSync}
*/
#countEntriesQuery
/**
* @type {import('node:sqlite').StatementSync | null}
*/
#deleteOldValuesQuery
/**
* @param {import('../../types/cache-interceptor.d.ts').default.SqliteCacheStoreOpts | undefined} opts
*/
constructor (opts) {
if (opts) {
if (typeof opts !== 'object') {
throw new TypeError('SqliteCacheStore options must be an object')
}
if (opts.maxEntrySize !== undefined) {
if (
typeof opts.maxEntrySize !== 'number' ||
!Number.isInteger(opts.maxEntrySize) ||
opts.maxEntrySize < 0
) {
throw new TypeError('SqliteCacheStore options.maxEntrySize must be a non-negative integer')
}
if (opts.maxEntrySize > MAX_ENTRY_SIZE) {
throw new TypeError('SqliteCacheStore options.maxEntrySize must be less than 2gb')
}
this.#maxEntrySize = opts.maxEntrySize
}
View on GitHub (pinned to 1b2de5e052)
Solutions
- Pass an options object: new SqliteCacheStore({ location: '/var/cache.db', maxEntrySize, maxCount }).
- If you only need an in-memory DB, call new SqliteCacheStore() or new SqliteCacheStore(undefined) with no argument.
- If you have a bare path string, wrap it: new SqliteCacheStore({ location: path }).
- Verify your config loader returns an object (not a stringified JSON you forgot to parse).
Example fix
// before
const store = new SqliteCacheStore('/var/cache/undici.db')
// after
const store = new SqliteCacheStore({ location: '/var/cache/undici.db' }) Defensive patterns
Strategy: type-guard
Validate before calling
function makeSqliteStore(raw) {
const opts = raw == null || typeof raw === 'object' ? raw : null
if (opts === null) throw new TypeError('SqliteCacheStore options must be an object')
return new SqliteCacheStore(opts)
} Type guard
function isSqliteOpts(v) {
return v == null || (typeof v === 'object' && !Array.isArray(v))
} Prevention
- Pass an object literal { location, maxEntrySize, maxCount }.
- If you only have a path string, wrap it as { location: path }.
- Keep a typed factory function so the options shape is enforced.
- Treat null/undefined as 'no options'; never pass a scalar.
When it happens
Trigger: new SqliteCacheStore('/var/cache.db'), new SqliteCacheStore(123), new SqliteCacheStore(true), or new SqliteCacheStore([':memory:']). Reproduces whenever a config loader passes a scalar where an options object is expected.
Common situations: Confusing the location string with the options object (users assume the store takes a path directly); wiring a YAML/env config that yields a scalar; copy-paste from MemoryCacheStore which takes no options.
Related errors
- SqliteCacheStore options.maxEntrySize must be a non-negative
- SqliteCacheStore options.maxEntrySize must be less than 2gb
- SqliteCacheStore options.maxCount must be a non-negative int
- expected key to be object, got ${typeof key}
- MemoryCacheStore options must be an object
AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13).
Data as JSON: /api/errors/042fddaec5418507.
Report an issue: GitHub.