{"record":{"id":"9a1e2e2439308825","repo":"krisk/Fuse","slug":"token-search-is-not-available","errorCode":null,"errorMessage":"Token search is not available","messagePattern":"Token search is not available","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/index.ts","lineNumber":80,"sourceCode":"    options?: IFuseOptions<any>\n  ) => SearchResult\n\n  constructor(\n    docs: ReadonlyArray<T>,\n    options?: IFuseOptions<T>,\n    index?: FuseIndex<T>\n  ) {\n    this.options = { ...Config, ...options } as Required<IFuseOptions<T>>\n\n    if (\n      this.options.useExtendedSearch &&\n      !process.env.EXTENDED_SEARCH_ENABLED\n    ) {\n      throw new Error(ErrorMsg.EXTENDED_SEARCH_UNAVAILABLE)\n    }\n\n    if (this.options.useTokenSearch && !process.env.TOKEN_SEARCH_ENABLED) {\n      throw new Error(ErrorMsg.TOKEN_SEARCH_UNAVAILABLE)\n    }\n\n    this._keyStore = new KeyStore(this.options.keys)\n\n    this._docs = docs as T[]\n    this._myIndex = null as any\n    this._invertedIndex = null\n\n    this.setCollection(docs, index)\n\n    this._lastQuery = null\n    this._lastSearcher = null\n  }\n\n  _getSearcher(query: string): Searcher {\n    if (this._lastQuery === query) {\n      return this._lastSearcher!\n    }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/krisk/Fuse/blob/edf2fb608eca0461508d1d71317e6e58309ffada/src/core/index.ts#L62-L98","documentation":"Fuse.js gates token search behind the TOKEN_SEARCH_ENABLED environment variable. Constructing a Fuse instance with useTokenSearch: true without that env var set makes the constructor throw before any indexing. The feature code is excluded from builds that never enable the flag.","triggerScenarios":"Calling new Fuse(docs, { keys: [...], useTokenSearch: true }) while process.env.TOKEN_SEARCH_ENABLED is unset or falsy at construction time.","commonSituations":"Deployments where .env is not loaded; enabling token search after copying config from a project with the env var set; CI/staging environments missing the flag present in local dev.","solutions":["Set process.env.TOKEN_SEARCH_ENABLED to a truthy value ('1') before instantiating Fuse.","Remove useTokenSearch: true if token search is not required.","Verify dotenv or platform env config loads the variable in every environment where Fuse is constructed."],"exampleFix":"// before\nconst fuse = new Fuse(docs, { keys: ['name'], useTokenSearch: true })\n// after\nprocess.env.TOKEN_SEARCH_ENABLED = '1'\nconst fuse = new Fuse(docs, { keys: ['name'], useTokenSearch: true })","handlingStrategy":"validation","validationCode":"if (options.useTokenSearch && !process.env.TOKEN_SEARCH_ENABLED) {\n  throw new Error('Set TOKEN_SEARCH_ENABLED before using useTokenSearch')\n}\nconst fuse = new Fuse(docs, options)","typeGuard":"const tokenSearchReady = () => Boolean(process.env.TOKEN_SEARCH_ENABLED)","tryCatchPattern":"try {\n  return new Fuse(docs, options)\n} catch (e) {\n  if (e.message === 'Token search is not available') {\n    process.env.TOKEN_SEARCH_ENABLED = '1'\n    return new Fuse(docs, options)\n  }\n  throw e\n}","preventionTips":["Set TOKEN_SEARCH_ENABLED in all deploy environments.","Keep feature flags and env vars in sync behind one config module.","Load dotenv at the process entry point."],"tags":["configuration","environment-variable","token-search"],"backgroundTag":"missing-env-var","analyzedSha":"edf2fb608eca0461508d1d71317e6e58309ffada","analyzedAt":"2026-09-02T02:46:54.623Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}