Skip to content

Drop the bundled provider's AMD branches, which fail Next.js builds with Turbopack - #12

Merged
betimd merged 1 commit into
mainfrom
fix/bundle-amd-define
Oct 23, 2026
Merged

betimd merged 1 commit into
mainfrom
fix/bundle-amd-define

Conversation

@betimd

@betimd betimd commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

@sentdm/voice-client 0.2.0 doesn't build in a Next.js 16 app with Turbopack: 114 Can't resolve './core' errors.

The bundled adapter/sinch-rtc.{js,mjs} still carries the UMD wrappers of crypto-js and ulid. That's 37 per file, each with an AMD branch such as typeof define=="function"&&define.amd?define(["./core"],t):…. No browser takes that branch, but Turbopack resolves the file names it lists. Vite and Rollup ignore it, which is why examples/browser-phone builds.

  • scripts/bundle.mjs sets define: { define: 'undefined' }, so esbuild drops the branch. Nothing else in the bundle reads a global define: every free define before this change belonged to one of the 37 wrappers. The bundle is about 3 KB smaller.
  • tests/dist.test.ts fails if either bundle contains a free define([...]) call, and lists the calls it finds. Without the fix it fails on both formats.
  • Checked against a minimal Next.js 16.3.4 app with Turbopack, which imports the client with dynamic(..., { ssr: false }) as the samples do:
    • with 0.2.0 from npm, 114 errors;
    • with this build, 0.
  • Not covered here: importing the client into a server-rendered component (no ssr: false) still fails under Turbopack, with 0.2.0 and with this fix. Pubnub's Node entry pulls in formidable, whose dynamic require(path.join(__dirname, 'plugins', …)) Turbopack can't resolve. Worth a docs note.

Release: the commit is fix:, so release-please makes this 0.2.1 for all three linked packages. Merge with a merge commit, not a squash, so release-please still sees the fix: subject. The automatic npm publish failed with ENEEDAUTH for 0.2.0 and went out from a manual run, so 0.2.1 is the first automatic OIDC publish. If it fails again, rerun publish-npm by hand on main.

Once 0.2.1 is on npm, the samples (sent-dm-voice-samples-apps) can drop their voice-client-amd-loader.cjs workaround.

Part of EPIC-4426 (Sent Voice): https://github.com/sentdm/sent-dm-agentic-org/blob/main/_pm/epics/EPIC-4426-sent-voice.md

How to test

  • ./scripts/test: 286 pass, including the new dist check on both formats
  • ./scripts/lint
  • pnpm pack the voice-client package, install the tarball into a Next.js 16 app, import it with dynamic(..., { ssr: false }), and run next build. It succeeds, where 0.2.0 fails with 114 errors

…lds with Turbopack

crypto-js and ulid, which sinch-rtc uses, are UMD, and kept their AMD
branch in the bundled adapter: typeof define=="function"&&define.amd?
define(["./core"],t):…. No browser takes it, but Turbopack resolves the
file names it lists, so a Next.js 16 app importing @sentdm/voice-client
0.2.0 failed its build with 114 "Can't resolve './core'" errors. Vite and
Rollup ignore them.

The bundle now defines the global define as undefined, so esbuild drops
all 37 branches from adapter/sinch-rtc.js and .mjs. Nothing else in the
bundle reads a global define.

- A dist test fails if either adapter build makes an AMD define([...]) call
- Apps can drop the Turbopack loader that stripped the branch
@betimd
betimd merged commit 343932c into main Oct 23, 2026
6 checks 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