krisk/Fuse · error · Error
Incorrect 'index' type
Error message
Incorrect 'index' type
What it means
Fuse.setCollection(docs, index) accepts an optional pre-built index as its second argument, but it must be a genuine FuseIndex instance. Passing anything else (plain object, array, index from a different Fuse copy) throws this error so a malformed index is never silently used. It exists to catch stale or hand-rolled index objects.
Source
Thrown at src/core/index.ts:112
_getSearcher(query: string): Searcher {
if (this._lastQuery === query) {
return this._lastSearcher!
}
const opts = this._invertedIndex
? { ...this.options, _invertedIndex: this._invertedIndex }
: this.options
const searcher = createSearcher(query, opts)
this._lastQuery = query
this._lastSearcher = searcher
return searcher
}
setCollection(docs: ReadonlyArray<T>, index?: FuseIndex<T>): void {
this._docs = docs as T[]
if (index && !(index instanceof FuseIndex)) {
throw new Error(ErrorMsg.INCORRECT_INDEX_TYPE)
}
this._myIndex =
index ||
createIndex(this.options.keys, this._docs, {
getFn: this.options.getFn,
fieldNormWeight: this.options.fieldNormWeight
})
if (this.options.useTokenSearch) {
const analyzer = createAnalyzer({
isCaseSensitive: this.options.isCaseSensitive,
ignoreDiacritics: this.options.ignoreDiacritics,
tokenize: this.options.tokenize
})
this._invertedIndex = buildInvertedIndex(
this._myIndex.records,
this._myIndex.keys.length,View on GitHub (pinned to edf2fb608e)
Solutions
- Create the index with Fuse.createIndex(keys, docs) from the SAME installed Fuse module and pass that to setCollection.
- Omit the second argument and let Fuse build the index itself.
- Dedupe fuse.js in node_modules if instanceof mismatches come from multiple package copies.
Example fix
// before const index = buildMyOwnIndex(keys, docs) // plain object fuse.setCollection(newDocs, index) // after import Fuse from 'fuse.js' const index = Fuse.createIndex(['title'], newDocs) fuse.setCollection(newDocs, index)
Defensive patterns
Strategy: type-guard
Validate before calling
import Fuse, { FuseIndex } from 'fuse.js'
if (index !== undefined && !(index instanceof FuseIndex)) {
throw new TypeError('setCollection requires a FuseIndex from Fuse.createIndex')
}
fuse.setCollection(docs, index) Type guard
const isFuseIndex = (v) => v instanceof FuseIndex
Try / catch
try {
fuse.setCollection(docs, index)
} catch (e) {
if (e.message === "Incorrect 'index' type") {
fuse.setCollection(docs) // let Fuse rebuild the index
} else {
throw e
}
} Prevention
- Always build indexes with Fuse.createIndex from the same module instance.
- Dedupe fuse.js in node_modules to avoid instanceof mismatches.
- Omit the index argument unless you hold a valid pre-built one.
When it happens
Trigger: fuse.setCollection(docs, someObject) where someObject is not created by Fuse.createIndex(...) — e.g. a serialized/cached index from a different Fuse version, a plain array, or a duplicate-package instanceof mismatch.
Common situations: Caching indexes built by a different installed copy of fuse.js (duplicate dependency causing instanceof to fail); hand-rolling an index object; upgrading Fuse while reusing old serialized indexes.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of krisk/Fuse@edf2fb608e (2026-09-02).
Data as JSON: /api/errors/e831b5384e834995.
Report an issue: GitHub.