Repository navigation
typechat/ts cannot be bundled for the browser: node:module import in the public validator entrypoint#534Description
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 theexportsmap that points at a build
withoutnode:module, keeping the Node build as the default; or - resolve the TypeScript compiler lazily through a small Node-only shim so the
typechat/tsmodule graph stays browser-resolvable.
Activity
robgruen commentedon Nov 23, 2026
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
undiciproxy 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.1compiler/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.