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

  1. Pass an options object: new SqliteCacheStore({ location: '/var/cache.db', maxEntrySize, maxCount }).
  2. If you only need an in-memory DB, call new SqliteCacheStore() or new SqliteCacheStore(undefined) with no argument.
  3. If you have a bare path string, wrap it: new SqliteCacheStore({ location: path }).
  4. 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

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


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/042fddaec5418507. Report an issue: GitHub.