{"record":{"id":"93e1de7732509add","repo":"krisk/Fuse","slug":"fuseworker-does-not-support-function-valued-option","errorCode":null,"errorMessage":"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.","messagePattern":"FuseWorker does not support function-valued option '(.+?)': functions cannot be transferred to Web Workers via postMessage\\. Remove this option or fall back to Fuse\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/workers/FuseWorker.ts","lineNumber":116,"sourceCode":"  ) {\n    this._docs = docs.slice()\n    this._options = options || ({} as IFuseOptions<T>)\n    this._workerOptions = workerOptions || {}\n    // Reject function-valued options eagerly. Without this check, postMessage\n    // throws DataCloneError on first search() rather than at construction.\n    FuseWorker._assertNoFunctionOptions(this._options)\n    // Token search needs global corpus statistics, but each shard would build\n    // its own — scores would diverge from single-thread Fuse. Refuse upfront\n    // rather than silently returning ordering that doesn't match.\n    if (this._options.useTokenSearch) {\n      throw new Error(ErrorMsg.FUSE_WORKER_TOKEN_SEARCH_UNSUPPORTED)\n    }\n    this._workerUrl = this._workerOptions.workerUrl || resolveDefaultWorkerUrl()\n  }\n\n  private static _assertNoFunctionOptions<U>(options: IFuseOptions<U>): void {\n    if (typeof (options as { sortFn?: unknown }).sortFn === 'function') {\n      throw new Error(ErrorMsg.FUSE_WORKER_UNSUPPORTED_FN_OPTION('sortFn'))\n    }\n    if (typeof (options as { getFn?: unknown }).getFn === 'function') {\n      throw new Error(ErrorMsg.FUSE_WORKER_UNSUPPORTED_FN_OPTION('getFn'))\n    }\n    if (typeof (options as { tokenize?: unknown }).tokenize === 'function') {\n      throw new Error(ErrorMsg.FUSE_WORKER_UNSUPPORTED_FN_OPTION('tokenize'))\n    }\n    const keys = options.keys\n    if (Array.isArray(keys)) {\n      for (let i = 0, len = keys.length; i < len; i += 1) {\n        const key = keys[i] as FuseOptionKey<U>\n        if (key && typeof key === 'object' && !Array.isArray(key)) {\n          if (typeof (key as { getFn?: unknown }).getFn === 'function') {\n            const name = (key as { name?: string | string[] }).name\n            const label = Array.isArray(name)\n              ? name.join('.')\n              : (name ?? String(i))\n            throw new Error(","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/krisk/Fuse/blob/edf2fb608eca0461508d1d71317e6e58309ffada/src/workers/FuseWorker.ts#L98-L134","documentation":"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').","triggerScenarios":"Thrown at src/workers/FuseWorker.ts:116 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"edf2fb608eca0461508d1d71317e6e58309ffada","analyzedAt":"2026-09-02T02:46:54.623Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}