Skip to content

typechat/ts cannot be bundled for the browser: node:module import in the public validator entrypoint #534

Todo
1 of 1 issue completed

Description

@soarkit

Current status: experimental prototype available

Open - experimental prototype available (2026-11-30).

The opt-in browser/WASM prototype was merged in #538. It is a private, source-only experiment outside the normal npm workspaces, not a published or production-supported browser package. Build/link it from source using the prototype setup and limitations.

This is progress toward this report, not a complete fix for the public typechat/ts browser entrypoint. The default Node backend remains native; installing the published typechat package does not include the experimental adapter. Support, public API/package integration, compatibility, and deployment/cost decisions remain tracked in #536.

This issue remains open for the original public browser-bundling request. The experimental merge does not imply a supported-release commitment.


Repository: microsoft/TypeChat
Component: typescript package (typechat), export typechat/ts
Version: typescript/package.json 0.1.4
Environment: Node.js 22.23.5, npm 10.9.9, esbuild 0.28.2, Linux (node:22-bookworm)

Summary

The public typechat/ts entrypoint transitively imports node:module (via
createRequire). Bundlers targeting the browser cannot resolve that module, so
an application that imports typechat/ts cannot be built for a web target.

Root cause

typescript/src/ts/validate.ts:1:

import { createRequire } from 'node:module';
...
const requireEsm = createRequire(__filename);

The CommonJS build emits require("node:module") into dist/ts/validate.js,
which browser bundlers cannot resolve.

typescript/package.json declares the export without a browser condition:

"exports": {
  ".": "./dist/index.js",
  "./ts": "./dist/ts/index.js",
  "./zod": "./dist/zod/index.js",
  "./interactive": "./dist/interactive/index.js"
}

git log -S "node:module" -- typescript/src/ts/validate.ts points to commit
83caa1242d9a9a707a4a66bfbc5fe6174cbcb8dc ("Update Node.js version and
dependencies, remove EOL versions (#428)", 2026-08-21). The import is present
in the current revision
(a89f12602bd3d5ce3805e41a2c337cd6bdb95693), so the public entrypoint has
been unbundleable for browser targets since that change.

Expected behavior

Bundling the typechat/ts entrypoint for a browser target should succeed, or
the package should expose a browser-safe entrypoint for that export.

Actual behavior

git clone https://github.com/microsoft/TypeChat.git
cd TypeChat && git checkout a89f12602bd3d5ce3805e41a2c337cd6bdb95693
cd typescript
npm ci
npm run build

npx esbuild dist/ts/index.js --bundle --platform=browser --format=esm \
    --outfile=/tmp/browser-ts.js
✘ [ERROR] Could not resolve "node:module"

    dist/ts/validate.js:4:30
      4 │ const node_module_1 = require("node:module");
        ╵        ~~~~~~~~~~~~~

  The package "node:module" wasn't found on the file system but is built
  into node. Are you trying to bundle for node? You can use "--platform=node"
  to do that, which will remove this error.

The same entrypoint bundles successfully with --platform=node --format=cjs
(output: 19,275 bytes), confirming the failure is specific to browser targets.

Suggested fix

  • Add a "browser" condition to the exports map that points at a build
    without node:module, keeping the Node build as the default; or
  • resolve the TypeScript compiler lazily through a small Node-only shim so the
    typechat/ts module graph stays browser-resolvable.

Sub-issues

Sub-issues

1 of 1 Issues completed
Loading 1 sub-issues

Activity

  1. robgruen commented on Nov 23, 2026

    @robgruen
    Contributor

    Thanks for reporting this. We investigated the browser path against dddb7f7. That build still failed browser bundling with TypeScript 7.0.2: although the specific import in the report has changed, the compiler backend still depends on Node APIs. There is also a separate bundling concern around the optional Node-only undici proxy dependency.

    There is a promising route forward. Upstream microsoft/TypeScript#64174 adds a WASM reactor. An isolated prototype retained TypeChat's validation logic behind a test-only API/filesystem/transport adapter and passed eight real-browser validation, repair, and schema-preflight cases, with no Node globals or live model calls.

    This is feasibility evidence, not a production-ready fix. The prototype required matching experimental 7.1.0-dev.20261030.1 compiler/WASM packages and excluded Node proxy support. The WASM artifact is approximately 53 MB raw / 13.4 MB gzipped. Publication alone does not establish a stable, supported WASM API.

    I've opened #536 as a sub-issue to investigate an opt-in adapter and a possible isolated-branch prototype, including compatibility, asset loading, measured costs, and explicit criteria for any later merge. The existing Node backend should remain unchanged. We'll keep this issue open while that investigation proceeds; this is not a commitment to ship an experimental compiler or merge a prototype automatically.

  2. added
    experimental
    on Nov 30, 2026
  3. self-assigned this
    on Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

experimental

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions