krisk/Fuse · error · Error

Extended search is not available

Error message

Extended search is not available

What it means

Fuse.js gates extended search (operator syntax like $contains, $eq) behind the EXTENDED_SEARCH_ENABLED environment variable so builds that don't need the feature can exclude it. If you construct a Fuse instance with useExtendedSearch: true while that env var is unset, the constructor throws immediately. This is an intentional opt-in contract, not a bug.

Source

Thrown at src/core/index.ts:76

  static use: (...plugins: any[]) => void
  static match: (
    pattern: string,
    text: string,
    options?: IFuseOptions<any>
  ) => SearchResult

  constructor(
    docs: ReadonlyArray<T>,
    options?: IFuseOptions<T>,
    index?: FuseIndex<T>
  ) {
    this.options = { ...Config, ...options } as Required<IFuseOptions<T>>

    if (
      this.options.useExtendedSearch &&
      !process.env.EXTENDED_SEARCH_ENABLED
    ) {
      throw new Error(ErrorMsg.EXTENDED_SEARCH_UNAVAILABLE)
    }

    if (this.options.useTokenSearch && !process.env.TOKEN_SEARCH_ENABLED) {
      throw new Error(ErrorMsg.TOKEN_SEARCH_UNAVAILABLE)
    }

    this._keyStore = new KeyStore(this.options.keys)

    this._docs = docs as T[]
    this._myIndex = null as any
    this._invertedIndex = null

    this.setCollection(docs, index)

    this._lastQuery = null
    this._lastSearcher = null
  }

View on GitHub (pinned to edf2fb608e)

Solutions

  1. Set the environment variable EXTENDED_SEARCH_ENABLED to a truthy value ('1') before constructing Fuse.
  2. Remove useExtendedSearch: true from options if operator syntax is not needed.
  3. Ensure the env var is provisioned at build/runtime (dotenv, DefinePlugin, platform config) in every environment.

Example fix

// before
const fuse = new Fuse(list, { keys: ['title'], useExtendedSearch: true })
// after
process.env.EXTENDED_SEARCH_ENABLED = '1'
const fuse = new Fuse(list, { keys: ['title'], useExtendedSearch: true })
Defensive patterns

Strategy: validation

Validate before calling

if (options.useExtendedSearch && !process.env.EXTENDED_SEARCH_ENABLED) {
  throw new Error('Set EXTENDED_SEARCH_ENABLED before using useExtendedSearch')
}
const fuse = new Fuse(docs, options)

Type guard

const extendedSearchReady = () => Boolean(process.env.EXTENDED_SEARCH_ENABLED)

Try / catch

try {
  return new Fuse(docs, options)
} catch (e) {
  if (e.message === 'Extended search is not available') {
    process.env.EXTENDED_SEARCH_ENABLED = '1'
    return new Fuse(docs, options)
  }
  throw e
}

Prevention

When it happens

Trigger: Calling new Fuse(docs, { keys: [...], useExtendedSearch: true }) in a process where process.env.EXTENDED_SEARCH_ENABLED is unset or falsy at construction time.

Common situations: .env files not loaded in the deployed environment; bundlers stripping env vars so the flag never reaches the client; copying a config with useExtendedSearch:true from a project that had the env var set.

Understand the failure class

Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of krisk/Fuse@edf2fb608e (2026-09-02). Data as JSON: /api/errors/1a474e732ce3ee03. Report an issue: GitHub.