Skip to content

Edge & serverless

TeX can’t run on the edge — there’s no child process to spawn. platex handles this with a dedicated edge-safe entry point that only ever talks to the remote service.

This entry point exposes the same client and handler API as the Node entry, but remote-only. It never imports node:child_process, node:fs, or node:os, so it’s safe to bundle for any runtime with a global fetch:

  • Vercel / Next.js Edge Runtime
  • Cloudflare Workers
  • Bun and Deno
  • Browsers
app/api/compile/route.ts — Edge Runtime
export const runtime = 'edge';
import { handleCompileRequest } from '@nandan-varma/platex/client';
export const POST = handleCompileRequest;

Or with a configured client:

export const runtime = 'edge';
import { createPlatexClient, createRequestHandler } from '@nandan-varma/platex/client';
const platex = createPlatexClient({ timeout: 20_000, retry: 2 });
export const POST = createRequestHandler(platex);

Because there’s no local compilation on the edge, the client needs a service to call. If you invoke .compile() without a serviceUrl configured (and none in PLATEX_SERVICE_URL), it throws immediately with a clear message telling you what’s missing — rather than trying, and failing, to spawn a TeX process that can’t exist on that runtime.

import { createPlatexClient } from '@nandan-varma/platex/client';
const platex = createPlatexClient({
serviceUrl: 'https://your-platex-service.vercel.app',
});
@nandan-varma/platex @nandan-varma/platex/client
Runtime Node.js anything with fetch
Local compilation ✅ system TeX / bundled Tectonic ❌ never
Remote compilation
Node built-ins imported yes none
No serviceUrl behavior falls back to local compile throws a clear error

If you’re contributing or bundling manually, you can confirm the client build pulls in no Node built-ins after building:

Terminal window
grep -n "require(\|from '" dist/client.js # should show no node: specifiers