Skip to content

fix(client-sdk): externalize all Node builtins in Vite lib build - #26234

Merged
charlesBochet merged 3 commits into
twentyhq:mainfrom
AyeshaWaseemAhmad:fix/client-sdk-node-loadable-build
Sep 21, 2026
Merged

charlesBochet merged 3 commits into
twentyhq:mainfrom
AyeshaWaseemAhmad:fix/client-sdk-node-loadable-build

Conversation

@AyeshaWaseemAhmad

@AyeshaWaseemAhmad AyeshaWaseemAhmad commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Issue #25824: On external-fork PRs, server integration tests fail before any
test runs while loading the freshly built twenty-client-sdk. Every shard dies
with:

Error: Module "" has been externalized for browser compatibility. Cannot access ".custom" in client code.

The stack points into packages/twenty-client-sdk/dist/application-*.js. It
reproduces across unrelated contributors and forks, blocking green CI for
changes that have nothing to do with the SDK.

Root cause

twenty-client-sdk is built with Vite in lib mode, which resolves for the
browser by default. When a Node builtin ends up in a chunk and is not marked
external, Vite replaces it with a browser stub that throws
Module … has been externalized for browser compatibility. Cannot access … in client code. the moment the property is accessed. The SDK also runs in Node —
the server imports it during app sync and server integration tests — so that
stub blows up on load.

vite.shared.ts only externalized five builtins (node:fs/promises, node:fs,
node:path, node:os, node:url). Any other builtin pulled into a chunk was
left to be browser-stubbed. Which builtins get bundled depends on dependency
hoisting, so this only surfaces on fresh, uncached installs (external-fork CI);
internal runs that restore the SDK build from cache never exercise the path,
which is why the issue looked contributor-independent and intermittent.

Solution

  • In vite.shared.ts, externalize all Node builtins via builtinModules
    from node:module (both bare and node:-prefixed forms), instead of the
    hardcoded five. This keeps them as real imports the host environment resolves,
    so Vite can never emit a browser stub for a builtin regardless of how
    dependencies hoist.

Testing

  • Fresh vite build (both the main and vite.metadata.config.ts configs)
    succeeds and produces dist artifacts byte-identical to the committed ones —
    no regression — with no externalization stub present.
  • npx vitest run --root packages/twenty-client-sdk — 104/104 pass.
  • Note: the original failure only manifests in the external-fork CI
    environment's dependency resolution and could not be reproduced locally (a
    clean local build was already stub-free), so the definitive check is a fresh
    external-fork CI run of the server integration tests.

Fixes #25824

Review in cubic

@twenty-ci-bot-public

Copy link
Copy Markdown

👋 Thanks for contributing to Twenty!

Your PR has been set to draft while you work on it. Once you're done, mark it as Ready for review and our automated checks will run.

Looking forward to your contribution!

@greptile-apps

greptile-apps Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The implementation appears safe to merge, with a non-blocking request to add regression coverage for the externalization behavior.

Findings

  1. P2 Missing Externalization Regression Coverage ▶

Summary

This PR replaces a small hardcoded list of external Node modules with comprehensive builtin detection for both bare and node:-prefixed specifiers.

  • Applies the externalization logic to both SDK Vite library builds through their shared configuration.
  • Prevents Vite from substituting browser compatibility stubs for Node builtins used by Node consumers.
  • Leaves the new regression-sensitive behavior without focused or artifact-level test coverage.

Reviews (1) · Last reviewed commit: "fix(client-sdk): externalize all Node bu..."

Comment on lines +15 to +21
const nodeBuiltins = new Set<string>([
...builtinModules,
...builtinModules.map((moduleName) => `node:${moduleName}`),
]);

const isNodeBuiltin = (id: string) =>
id.startsWith('node:') || nodeBuiltins.has(id);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Missing Externalization Regression Coverage

The new builtin externalization behavior has no focused regression coverage, and the existing build and tests do not inspect generated artifacts for Vite browser stubs or preserved builtin imports. This leaves room for a future change to silently restore the external-fork runtime failure while the package build and unit tests remain green. Please cover both bare and node:-prefixed builtins, or add an artifact-level assertion.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@twenty-ci-bot-public

twenty-ci-bot-public Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

🤖 PR Review

Check Result
🔍 Build safety ✅ passed
🛡️ Security ⏭️ skipped — trusted-only
🧭 Triage ✅ passed
📐 Quality ⏭️ skipped — trusted-only
🚦 Auto-approve ⏭️ skipped — trusted-only

🔍 Automated Pre-Review

✅ No issues detected - This PR is ready for human review.


🧭 External PR Triage Review

✅ Looks good — a maintainer can pick this up.

Checks

  • ⏳ CI: pending
  • 🔗 Linked issue: Fixes #25824

Detailed findings (duplicate candidates, standards notes, summary) are in the workflow run logs.


View details

Automated pre-review — human approval still required.

@charlesBochet
charlesBochet force-pushed the fix/client-sdk-node-loadable-build branch from c153065 to 8dd3f2c Compare September 21, 2026 13:05

@charlesBochet charlesBochet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@charlesBochet
charlesBochet added this pull request to the merge queue Sep 21, 2026
Merged via the queue into twentyhq:main with commit bfa9496 Sep 21, 2026
142 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CI: external-fork server integration tests fail loading freshly built twenty-client-sdk

2 participants