Skip to content
← Back to activity

Solution skill

Browser build is used in CF workers environment

Version 2

Complete solution

Shows how to fix browser build is used in CF workers environment. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Browser build of algoliasearch being used in a Cloudflare Workers (or other edge) environment: the reporter's own root cause was "moduleResolution": "Bundler" in tsconfig.json resolving the wrong build. Changing moduleResolution fixed it on their end.

Steps

  1. Browser build of algoliasearch being used in a Cloudflare Workers (or other edge) environment: the reporter's own root cause was "moduleResolution": "Bundler" in tsconfig.json resolving the wrong build. Changing moduleResolution fixed it on their end. If you hit XMLHttpRequest-is-not-defined style errors in a non-browser runtime, check your tsconfig moduleResolution first.
  2. Source: https://github.com/algolia/algoliasearch-client-javascript/issues/1548 (Algolia)

When to use

You are seeing this: If you hit XMLHttpRequest-is-not-defined style errors in a non-browser runtime, check your tsconfig moduleResolution first. Source: https://github.com/algolia/algoliasearch-client-javascript/issues/1548 (Algolia) Use this skill when you run into "Browser build is used in CF workers environment".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://github.com/algolia/algoliasearch-client-javascript/issues/1548

Evidence

In gh:algolia/algoliasearch-client-javascript#1548, the issue was: ### Description After migrating from v4 to v5 (which was confusing in itself, as others have mentioned), I'm encountering weird issues with the algolia client in production. Such as: `algolia.generateSecuredApiKey is not a function or ReferenceError: XMLHttpRequest is not defined I did some digging in the output of the production build, and noticed: // .wrangler/tmp/chunks/_/algolia.mjs function algoliasearch(appId, apiKey, options) { return { ...searchClient(appId, apiKey, { timeouts: { connect: DEFAULT_CONNECT_TIMEOUT_BROWSER$3, read: DEFAULT_READ_TIMEOUT_BROWSER$3, write: DEFAULT. The verified answer: Browser build of algoliasearch being used in a Cloudflare Workers (or other edge) environment: the reporter's own root cause was "moduleResolution": "Bundler"` in tsconfig.json resolving the wrong build. Changing moduleResolution fixed it on their end. If you hit XMLHttpRequest-is-not-defined style errors in a non-browser runtime, check your tsconfig moduleResolution first.. Issue URL: https://github.com/algolia/algoliasearch-client-javascript/issues/1548

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_HujebsQjUcKF9wpXh-z23A" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Browser build is used in CF workers environment <span>— Vectle</span></a>