{"record":{"id":"af233333f73f5c88","repo":"krisk/Fuse","slug":"fuseworker-unable-to-resolve-the-worker-script-ur","errorCode":null,"errorMessage":"FuseWorker: unable to resolve the worker script URL automatically; pass workerOptions.workerUrl explicitly.","messagePattern":"FuseWorker: unable to resolve the worker script URL automatically; pass workerOptions\\.workerUrl explicitly\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/workers/FuseWorker.ts","lineNumber":76,"sourceCode":"  // script, NOT via import.meta.url: its CJS rewrite (require('url')/__filename)\n  // can be polyfilled by browser bundlers (webpack/browserify) to a virtual path,\n  // which would silently win over the real script location. So when this is the\n  // CJS output and a document is present (browser-CJS), prefer the captured base.\n  // This matches the old Rollup CJS shim, which always preferred document in the\n  // browser. The ESM build keeps the import.meta.url literal below so bundlers\n  // detect + rewrite the worker asset (browser-ESM) and Node resolves it natively.\n  if (__WORKER_IS_CJS__ && browserWorkerBase !== undefined) {\n    return new URL('./fuse.worker.mjs', browserWorkerBase)\n  }\n  try {\n    // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n    // @ts-ignore -- import.meta.url is provided by the bundler per output format\n    return new URL('./fuse.worker.mjs', import.meta.url)\n  } catch {\n    if (browserWorkerBase !== undefined) {\n      return new URL('./fuse.worker.mjs', browserWorkerBase)\n    }\n    throw new Error(\n      'FuseWorker: unable to resolve the worker script URL automatically; ' +\n        'pass workerOptions.workerUrl explicitly.'\n    )\n  }\n}\n\nexport default class FuseWorker<T> {\n  private _options: IFuseOptions<T>\n  private _workerOptions: FuseWorkerOptions\n  private _docs: T[]\n  private _shards: Shard[] | null = null\n  private _addCursor = 0\n  private _initPromise: Promise<void> | null = null\n  private _pending: Map<number, PendingCall> = new Map()\n  private _nextId = 0\n  private _workerUrl: string | URL\n\n  constructor(","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/krisk/Fuse/blob/edf2fb608eca0461508d1d71317e6e58309ffada/src/workers/FuseWorker.ts#L58-L94","documentation":"Thrown by resolveDefaultWorkerUrl (invoked from the FuseWorker constructor) when every automatic strategy for locating the fuse.worker.mjs script fails: the CJS browser base captured at load time is absent and constructing the URL from import.meta.url throws. This happens in non-standard environments — bundlers that strip import.meta, sandboxed/no-document contexts, or unusual module formats — where the library cannot infer where the worker asset was emitted.","triggerScenarios":"Thrown at src/workers/FuseWorker.ts:76 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass the URL explicitly: new FuseWorker(docs, options, { workerUrl: new URL('./fuse.worker.mjs', import.meta.url) })","Copy the fuse.worker.mjs asset next to your bundle (or emit it via your bundler's worker support) so the default resolution can find it","Check that the environment provides either import.meta.url (ESM) or a document base (browser CJS); if not, workerUrl is mandatory","Serve the page over http(s) — file:// URLs cannot construct valid worker script URLs in most browsers"],"exampleFix":null,"handlingStrategy":"try-catch","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"}