nodejs/node · error · TypeError

SqliteCacheStore options.maxEntrySize must be a non-negative

Error message

SqliteCacheStore options.maxEntrySize must be a non-negative integer

What it means

Thrown when opts.maxEntrySize is defined but is not a safe non-negative integer. The guard requires typeof === 'number', Number.isInteger(...) true, and value >= 0; failing any one throws. maxEntrySize bounds the size of a single cached response body in bytes.

Source

Thrown at deps/undici/src/lib/cache/sqlite-cache-store.js:90

   */
  #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
      }

      if (opts.maxCount !== undefined) {
        if (
          typeof opts.maxCount !== 'number' ||
          !Number.isInteger(opts.maxCount) ||
          opts.maxCount < 0
        ) {
          throw new TypeError('SqliteCacheStore options.maxCount must be a non-negative integer')
        }
        this.#maxCount = opts.maxCount

View on GitHub (pinned to 1b2de5e052)

Solutions

  1. Pass an integer byte count: new SqliteCacheStore({ maxEntrySize: 1024 * 1024 }).
  2. If reading from config, coerce explicitly: Number.parseInt(process.env.MAX_ENTRY, 10).
  3. Omit maxEntrySize entirely to accept the default cap.
  4. Double-check you are not passing KB/MB units — the value is raw bytes.

Example fix

// before
new SqliteCacheStore({ maxEntrySize: '1MB' })
// after
new SqliteCacheStore({ maxEntrySize: 1024 * 1024 })
Defensive patterns

Strategy: validation

Validate before calling

function coerceMaxEntrySize(v) {
  const n = Number(v)
  if (!Number.isInteger(n) || n < 0) {
    throw new TypeError('maxEntrySize must be a non-negative integer (bytes)')
  }
  return n
}

Type guard

function isValidMaxEntrySize(v) {
  return typeof v === 'number' && Number.isInteger(v) && v >= 0
}

Prevention

When it happens

Trigger: Passing maxEntrySize as a float (1.5e6), a string ('1000'), a negative number, NaN, or Infinity. Also triggers with BigInt since typeof BigInt is 'bigint' not 'number'.

Common situations: Reading size from env vars as a string and forgetting to convert; mixing units (passing KB instead of bytes); using a decimal because 1.5 MB was the intent.

Related errors


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