Repository navigation
fix(client-sdk): externalize all Node builtins in Vite lib build - #26234
charlesBochet merged 3 commits into
Conversation
|
👋 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! |
|
| const nodeBuiltins = new Set<string>([ | ||
| ...builtinModules, | ||
| ...builtinModules.map((moduleName) => `node:${moduleName}`), | ||
| ]); | ||
|
|
||
| const isNodeBuiltin = (id: string) => | ||
| id.startsWith('node:') || nodeBuiltins.has(id); |
There was a problem hiding this comment.
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!
🤖 PR Review
🔍 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
Detailed findings (duplicate candidates, standards notes, summary) are in the workflow run logs. Automated pre-review — human approval still required. |
c153065 to
8dd3f2c
Compare
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 dieswith:
The stack points into
packages/twenty-client-sdk/dist/application-*.js. Itreproduces across unrelated contributors and forks, blocking green CI for
changes that have nothing to do with the SDK.
Root cause
twenty-client-sdkis built with Vite inlibmode, which resolves for thebrowser 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.tsonly externalized five builtins (node:fs/promises,node:fs,node:path,node:os,node:url). Any other builtin pulled into a chunk wasleft 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
vite.shared.ts, externalize all Node builtins viabuiltinModulesfrom
node:module(both bare andnode:-prefixed forms), instead of thehardcoded 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
vite build(both the main andvite.metadata.config.tsconfigs)succeeds and produces
distartifacts byte-identical to the committed ones —no regression — with no externalization stub present.
npx vitest run --root packages/twenty-client-sdk— 104/104 pass.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