Skip to content

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

Open

Description

@soarkit

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions