krisk/Fuse · error · Error
Fuse.match does not support useTokenSearch: token search req
Error message
Fuse.match does not support useTokenSearch: token search requires corpus-level statistics (df, fieldCount) that a one-off string comparison does not have. Use new Fuse(...).search(...) instead.
What it means
Fuse.match is a stateless one-off pattern-vs-string comparison helper. Token search requires corpus-level statistics (df, fieldCount) that a single string comparison cannot provide, so Fuse.match explicitly rejects options containing useTokenSearch. Without this guard the full build would crash with an opaque TypeError and the basic build would silently fall back to fuzzy matching; the supported path for token search is new Fuse(...).search(...).
Source
Thrown at src/entry.ts:26
import register, {
createSearcher,
registerObjectCompiler
} from './core/register'
import * as ErrorMsg from './core/errorMessages'
Fuse.version = __VERSION__
Fuse.createIndex = createIndex
Fuse.parseIndex = parseIndex
Fuse.config = Config
Fuse.match = function (pattern: string, text: string, options?: any) {
// Token search needs corpus statistics (df, fieldCount) that a one-off
// string comparison can't provide. Reject it here so the contract is the
// same in the full and basic builds — without this guard, the full build
// crashes with an opaque TypeError and the basic build silently falls back
// to fuzzy matching.
if (options && options.useTokenSearch) {
throw new Error(ErrorMsg.FUSE_MATCH_TOKEN_SEARCH_UNSUPPORTED)
}
const searcher = createSearcher(pattern, { ...Config, ...options })
return searcher.searchIn(text)
}
if (process.env.NODE_ENV === 'development') {
Fuse.parseQuery = parse
}
if (process.env.EXTENDED_SEARCH_ENABLED) {
register(ExtendedSearch)
registerObjectCompiler(compileObjectLeaf)
}
if (process.env.TOKEN_SEARCH_ENABLED) {
register(TokenSearch)
}
View on GitHub (pinned to edf2fb608e)
Solutions
- Remove useTokenSearch from the options passed to Fuse.match (strip the flag from shared configs).
- Use new Fuse([{ text }], { keys: ['text'], useTokenSearch: true }).search(pattern) when token search is genuinely needed.
- Keep token-search flags only on the instance config and pass a sanitized object to Fuse.match.
Example fix
// before
Fuse.match('world', text, options) // options.useTokenSearch === true
// after
const { useTokenSearch, ...safeOptions } = options
Fuse.match('world', text, safeOptions)
// or, for token search:
new Fuse([{ text }], { keys: ['text'], useTokenSearch: true }).search('world') Defensive patterns
Strategy: validation
Validate before calling
if (options && options.useTokenSearch) {
throw new Error('useTokenSearch is unsupported in Fuse.match; use new Fuse(...).search(...)')
}
Fuse.match(pattern, text, options) Type guard
const isMatchSafeOptions = (o) => !o || o.useTokenSearch !== true
Try / catch
try {
return Fuse.match(pattern, text, options)
} catch (e) {
if (e.message.includes('useTokenSearch')) {
const { useTokenSearch, ...safe } = options || {}
return Fuse.match(pattern, text, safe)
}
throw e
} Prevention
- Strip feature flags from shared options before passing them to static helpers.
- Reserve useTokenSearch for instance-based search only.
- Document which options apply to static helpers vs instances.
When it happens
Trigger: Calling Fuse.match(pattern, text, options) where options.useTokenSearch is truthy — typically a shared config object that enables token search for the main Fuse instance being reused here.
Common situations: Passing shared options/config objects into Fuse.match; switching from instance search to the static helper while unknowingly carrying the flag; legacy code relying on the old silent fuzzy fallback.
Related errors
AI-assisted analysis of krisk/Fuse@edf2fb608e (2026-09-02).
Data as JSON: /api/errors/2d20ca7e8f4edc61.
Report an issue: GitHub.