Skip to content

fix: load the worker and browser entry without Node built-ins - #17

Merged
frontegg-david merged 1 commit into
release/2.3.xfrom
fix/worker-entry-browser-safe
Oct 5, 2026
Merged

frontegg-david merged 1 commit into
release/2.3.xfrom
fix/worker-entry-browser-safe

Conversation

@frontegg-david

Copy link
Copy Markdown
Contributor

Problem

vectoriadb/worker, and the root export under the browser / worker conditions, is documented as safe to bundle for browsers and V8 isolates. As published in 2.3.2 it isn't:

  • crypto: vectoria-tfidf.ts imports sanitizeObject from storage/serialization.utils.ts, and that file imports Node's crypto at load for hash(). esbuild with platform: browser fails with Could not resolve "crypto". An isolate without Node compatibility can't load the entry at all.
  • tslib: the build runs with importHelpers: true, so the output calls require("tslib"), but the package doesn't declare tslib. A clean install fails with Could not resolve "tslib".

FrontMCP found this while making vectoriadb a regular dependency of @frontmcp/sdk for skill search in the browser (agentfront/frontmcp#761, #762). With 2.3.2, the SDK's browser bundle failed at load on crypto.

Fix

  • New module: sanitizeObject moves to src/sanitize.utils.ts, which has no imports. storage/serialization.utils.ts re-exports it, so import { sanitizeObject } from 'vectoriadb' and the existing importers are unchanged. vectoria-tfidf.ts imports it from the new module.
  • tslib: libs/vectoriadb/package.json declares it (^2.8.1, the version the workspace already uses).

Verification

  • New spec: worker-entry.spec.ts loads ../worker with crypto, fs, fs/promises, path, os, child_process, net and stream mocked to throw, then runs a TF-IDF search through it. On release/2.3.x it fails with the worker entry required the Node built-in "crypto".
  • Full suite: nx test vectoriadb passes 12 suites, 378 tests.
  • Built package in a clean project: I bundled import { TFIDFVectoria } from 'vectoriadb/worker' with esbuild (--platform=browser, no externals, no tslib installed). It bundles and searches correctly. On 2.3.2 the same bundle fails on tslib, then on crypto.
  • Module graph: in the built output, worker.js, vectoria-tfidf.js, sanitize.utils.js and tfidf.embedding.service.js require only each other.

Publishing this as 2.3.3 unblocks the vectoriadb part of agentfront/frontmcp#762.

The worker entry is documented as safe for browsers and V8 isolates, but
vectoria-tfidf imported sanitizeObject from storage/serialization.utils,
which imports Node's crypto at load for hash(). Every browser bundle of
vectoriadb/worker (or of the root export under the browser condition)
failed on "crypto", and an isolate without Node compatibility could not
load it.

sanitizeObject now lives in its own module with no imports;
serialization.utils re-exports it, so the public API is unchanged. The
package also declares tslib, which the build's importHelpers output
requires but was never listed as a dependency.

A new spec loads the worker entry with every Node built-in mocked to
throw, and runs a TF-IDF search through it.
@coderabbitai

coderabbitai Bot commented Oct 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 67144c53-d1b0-42fd-a40e-fdf6e6c7da38

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@frontegg-david
frontegg-david merged commit 240ac09 into release/2.3.x Oct 5, 2026
3 checks passed
@frontegg-david
frontegg-david deleted the fix/worker-entry-browser-safe branch October 5, 2026 14:16
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Cherry-pick Created

A cherry-pick PR to main has been automatically created.

Please review and merge if this change should also be in main.

If the cherry-pick is not needed, close the PR.

frontegg-david added a commit to agentfront/frontmcp that referenced this pull request Oct 5, 2026
… browser

vectoriadb was an optional peer that the SDK loaded with a literal
import('vectoriadb') on the first skill search. A browser bundle of the
SDK therefore failed with 'Could not resolve "vectoriadb"' unless the
consumer installed it (#761), and installing it did not help: in 2.3.2
its worker entry imported Node's crypto and an undeclared tslib, fixed in
vectoriadb 2.3.3 (agentfront/vectoriadb#17).

vectoriadb (^2.3.3) is now a regular dependency. The SDK imports its
worker-safe entry, vectoriadb/worker: the TF-IDF/BM25 index the skill
search uses, with no dependencies beyond tslib and no Node built-ins. The
index is still created on the first search; the optional-peer loading
and the spec that pinned it are gone. The browser-bundle e2e app runs a
skill search in Chromium, and the skills, testing and create-skill pages
no longer call vectoriadb an optional peer.
frontegg-david added a commit to agentfront/frontmcp that referenced this pull request Oct 5, 2026
… build (#762)

* fix(sdk): build connect() clients without an HTTP host

connect() (and connectOpenAI() / connectClaude()) builds its server
through FrontMcpInstance.createForGraph(), which still selected the
Express-backed server provider. #748 made createDirect() and
createFetchHandler() pass serve: false; createForGraph() did not, so in
the browser build connect() failed with "ExpressHostAdapter is not
available in browser environments" (#761). It never listens, so it now
passes serve: false too. createEdgeMcp() already passed it.

* fix(sdk): start ConfigPlugin in the browser build

loadConfig() and loadEnvFiles() resolved .env, .env.local and
config.yml with pathResolve() from @frontmcp/utils, whose browser build
throws, so every ConfigPlugin failed at startup in a browser (#761).
Where the runtime context is the browser build, the file sources now
count as absent, and process.env is read only where it exists, so the
config comes from the schema defaults and process.env.

The browser-bundle e2e app runs connect() and a ConfigPlugin server in
Chromium. Its other result checks now wait for the page summary, as
the first ones do, instead of reading the results before the async
checks finish. The browser compatibility, config and build-for-browser
pages describe both entry points and the 'browser' runtime value.

* fix(sdk): make vectoriadb a dependency and bundle skill search in the browser

vectoriadb was an optional peer that the SDK loaded with a literal
import('vectoriadb') on the first skill search. A browser bundle of the
SDK therefore failed with 'Could not resolve "vectoriadb"' unless the
consumer installed it (#761), and installing it did not help: in 2.3.2
its worker entry imported Node's crypto and an undeclared tslib, fixed in
vectoriadb 2.3.3 (agentfront/vectoriadb#17).

vectoriadb (^2.3.3) is now a regular dependency. The SDK imports its
worker-safe entry, vectoriadb/worker: the TF-IDF/BM25 index the skill
search uses, with no dependencies beyond tslib and no Node built-ins. The
index is still created on the first search; the optional-peer loading
and the spec that pinned it are gone. The browser-bundle e2e app runs a
skill search in Chromium, and the skills, testing and create-skill pages
no longer call vectoriadb an optional peer.

* fix(sdk): import vectoriadb from its package root

The subpath vectoriadb/worker exists only in the package's exports map,
which moduleResolution "node" ignores. tsconfig.base.json uses it, so
the webpack builds that compile the SDK source, such as apps/demo,
failed with TS2307 "Cannot find module 'vectoriadb/worker'".

The SDK imports the package root instead. Its types resolve through the
package's types field under any resolution mode, and its exports map
lists the worker and browser conditions before import, so browser and
worker bundles still get the TF-IDF entry without Node built-ins; Node
gets the full entry. A browser bundle of the SDK includes only
vectoriadb's worker.js, vectoria-tfidf.js, tfidf.embedding.service.js
and sanitize.utils.js.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant