krisk/Fuse · error · Error
FuseWorker does not support function-valued option '${option
Error message
FuseWorker does not support function-valued option '${option}': functions cannot be transferred to Web Workers via postMessage. Remove this option or fall back to Fuse. What it means
Thrown by the static _assertNoFunctionOptions validator, called from the FuseWorker constructor, when a function-valued Fuse option is detected — sortFn, getFn, tokenize, or a per-key getFn in options.keys. The check runs eagerly at construction: functions are not structured-cloneable, so without this guard postMessage would throw DataCloneError later on the first search(). '${option}' names the exact offending option path (e.g. 'getFn' or 'keys[title].getFn').
Source
Thrown at src/workers/FuseWorker.ts:116
) {
this._docs = docs.slice()
this._options = options || ({} as IFuseOptions<T>)
this._workerOptions = workerOptions || {}
// Reject function-valued options eagerly. Without this check, postMessage
// throws DataCloneError on first search() rather than at construction.
FuseWorker._assertNoFunctionOptions(this._options)
// Token search needs global corpus statistics, but each shard would build
// its own — scores would diverge from single-thread Fuse. Refuse upfront
// rather than silently returning ordering that doesn't match.
if (this._options.useTokenSearch) {
throw new Error(ErrorMsg.FUSE_WORKER_TOKEN_SEARCH_UNSUPPORTED)
}
this._workerUrl = this._workerOptions.workerUrl || resolveDefaultWorkerUrl()
}
private static _assertNoFunctionOptions<U>(options: IFuseOptions<U>): void {
if (typeof (options as { sortFn?: unknown }).sortFn === 'function') {
throw new Error(ErrorMsg.FUSE_WORKER_UNSUPPORTED_FN_OPTION('sortFn'))
}
if (typeof (options as { getFn?: unknown }).getFn === 'function') {
throw new Error(ErrorMsg.FUSE_WORKER_UNSUPPORTED_FN_OPTION('getFn'))
}
if (typeof (options as { tokenize?: unknown }).tokenize === 'function') {
throw new Error(ErrorMsg.FUSE_WORKER_UNSUPPORTED_FN_OPTION('tokenize'))
}
const keys = options.keys
if (Array.isArray(keys)) {
for (let i = 0, len = keys.length; i < len; i += 1) {
const key = keys[i] as FuseOptionKey<U>
if (key && typeof key === 'object' && !Array.isArray(key)) {
if (typeof (key as { getFn?: unknown }).getFn === 'function') {
const name = (key as { name?: string | string[] }).name
const label = Array.isArray(name)
? name.join('.')
: (name ?? String(i))
throw new Error(View on GitHub (pinned to edf2fb608e)
Solutions
- Remove the function-valued option; rely on Fuse's built-in defaults (default getFn/tokenize/sortFn replicate single-thread behavior)
- Serialize the custom logic differently — for getFn, pre-compute the searchable strings yourself and index those instead
- Fall back to the single-threaded Fuse class, which supports function-valued options natively
- For per-key getFn, move the transformation into the data before constructing FuseWorker so no custom function is needed
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/workers/FuseWorker.ts:116 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of krisk/Fuse@edf2fb608e (2026-09-02).
Data as JSON: /api/errors/93e1de7732509add.
Report an issue: GitHub.