Skip to content

fix(next): split runtime-next into server and client entry points - #4

Merged
sagnik11 merged 1 commit into
mainfrom
posthog-code/next-client-server-split
Jul 23, 2026
Merged

fix(next): split runtime-next into server and client entry points#4
sagnik11 merged 1 commit into
mainfrom
posthog-code/next-client-server-split

Conversation

@sagnik11

Copy link
Copy Markdown
Member

Problem

Setting up @autter/runtime-next in a real Next.js app fails at build time. The package has a single barrel entry that imports @autter/runtime-node (the full Node OpenTelemetry SDK) and re-exports the browser tracker + React error boundary. The documented step 3 (import { initAutterBrowser, AutterErrorBoundary } from "@autter/runtime-next" in a client component) therefore drags the OTel SDK into the client bundle and the build dies on Node built-ins (fs cannot be resolved).

Fix

Split the package into two entry points — the same shape @sentry/nextjs / posthog-js use:

  • @autter/runtime-next (and alias @autter/runtime-next/server) — server-only: registerAutter, createAutterRelayRoute, captureServerException, captureServerMessage. Used in instrumentation.ts and route handlers, so the two server snippets in the README keep working unchanged.
  • @autter/runtime-next/client — browser tracker API + AutterErrorBoundary, bundled with a "use client" banner and zero Node imports.

Build moves from a one-liner to tsup.config.ts so the client entry gets its own banner/target. Verified the built dist/client.js starts with "use client"; and contains no references to OpenTelemetry, runtime-node, or fs.

Breaking change

Client components must now import from @autter/runtime-next/client instead of the root. Since the old root import never actually built in a client component, no working setup breaks. Package README, docs/GETTING-STARTED.md, and docs/INTEGRATIONS.md updated.


Created with PostHog Code

The single barrel export mixed @autter/runtime-node (Node OTel SDK) with
browser re-exports and the React error boundary, so the documented client
component import pulled the OTel SDK into the browser bundle and failed
the Next.js build (fs cannot be resolved).

- Root / ./server entry: registerAutter, createAutterRelayRoute,
  captureServerException/Message — server-only code paths.
- ./client entry: browser tracker API + AutterErrorBoundary, built with a
  "use client" banner and no Node imports.
- Docs updated to import client pieces from @autter/runtime-next/client.

Generated-By: PostHog Code
Task-Id: 74ac2be4-ebb7-4ac4-8db4-62b20460f276
@sagnik11
sagnik11 merged commit 1103467 into main Jul 23, 2026
1 check passed
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