Skip to content

Commit ae8f662

Browse files
committed
fix(collab-doc): copy the full yjs/lib0 stack into the app image
The seed/merge/persist routes run the converter (markdown <-> Yjs) server-side. yjs is a serverExternalPackage and the Next standalone tracer copies lib0 only partially — it drops the ESM subpath file lib0/logging.js that yjs.mjs imports via lib0's exports map, so the seed 500s ('Cannot find module lib0/logging') and every collaborative doc is stuck read-only. Verified in the running dev container: /app/node_modules/lib0 had 37/38 files, logging.js missing. outputFileTracingIncludes can't fix it — its globs resolve against apps/sim, but these deps hoist to the monorepo-root node_modules, so the glob matches nothing (my prior next.config attempt was a no-op; reverted). Instead COPY the complete lib0/yjs/y-protocols from the deps stage in the runner, overwriting the partial trace — the same pattern already used for isolated-vm.
1 parent 85e291d commit ae8f662

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

apps/sim/next.config.ts

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,6 @@ import {
88
getWorkflowExecutionCSPPolicy,
99
} from './lib/core/security/csp'
1010

11-
/**
12-
* Collab-doc converter deps (markdown ⇄ Yjs via headless TipTap). They are `serverExternalPackages`, and
13-
* the standalone tracer doesn't copy them — jsdom is a lazy `require`, and yjs's ESM resolves `lib0` via
14-
* subpath exports nft misses — so force them in or the file-doc routes 500 with MODULE_NOT_FOUND.
15-
*/
16-
const COLLAB_DOC_SERVER_TRACE = [
17-
'./node_modules/jsdom/**/*',
18-
'./node_modules/yjs/**/*',
19-
'./node_modules/lib0/**/*',
20-
'./node_modules/y-protocols/**/*',
21-
'./node_modules/@tiptap/**/*',
22-
]
23-
2411
/**
2512
* Dev-only escape hatch: when `SIM_DEV_MINIMAL_REGISTRY=1` (`bun run dev:minimal`),
2613
* swap the heavy block and tool registries for tiny curated variants via a
@@ -215,10 +202,15 @@ const nextConfig: NextConfig = {
215202
],
216203
outputFileTracingIncludes: {
217204
'/api/tools/stagehand/*': ['./node_modules/ws/**/*'],
218-
// These routes run the collab-doc converter server-side; see COLLAB_DOC_SERVER_TRACE.
219-
'/api/internal/file-doc/seed': COLLAB_DOC_SERVER_TRACE,
220-
'/api/internal/file-doc/merge': COLLAB_DOC_SERVER_TRACE,
221-
'/api/internal/file-doc/persist': COLLAB_DOC_SERVER_TRACE,
205+
// The seed, merge, and persist endpoints all lazily `require('jsdom')` (via the collab-doc
206+
// converter), which is invisible to the standalone file tracer, so force jsdom (and its transitive
207+
// deps, followed from its static requires) into the trace — otherwise a Docker/standalone build
208+
// omits it and the endpoint 500s with MODULE_NOT_FOUND. (The Yjs external stack — yjs/lib0/
209+
// y-protocols — is copied whole in docker/app.Dockerfile: its glob would resolve against apps/sim
210+
// but those deps hoist to the monorepo root, so a trace include can't reach them.)
211+
'/api/internal/file-doc/seed': ['./node_modules/jsdom/**/*'],
212+
'/api/internal/file-doc/merge': ['./node_modules/jsdom/**/*'],
213+
'/api/internal/file-doc/persist': ['./node_modules/jsdom/**/*'],
222214
'/*': [
223215
'./node_modules/sharp/**/*',
224216
'./node_modules/@img/**/*',

docker/app.Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/content ./apps/sim/conte
117117
# Copy isolated-vm native module (compiled for Node.js in deps stage)
118118
COPY --from=deps --chown=nextjs:nodejs /app/node_modules/isolated-vm ./node_modules/isolated-vm
119119

120+
# The collab-doc seed/merge/persist routes run the converter (markdown <-> Yjs) server-side. `yjs` is a
121+
# serverExternalPackage, and the Next standalone tracer copies it only partially — it misses ESM subpath
122+
# files that `yjs/dist/yjs.mjs` imports through `lib0`'s exports map (e.g. `lib0/logging`), so the seed
123+
# 500s ("Cannot find module 'lib0/logging'") and every collaborative doc is stuck read-only. Overwrite
124+
# the partial trace with the complete packages from the full install (outputFileTracingIncludes can't:
125+
# its globs resolve against apps/sim, but these deps hoist to the monorepo-root node_modules).
126+
COPY --from=deps --chown=nextjs:nodejs /app/node_modules/lib0 ./node_modules/lib0
127+
COPY --from=deps --chown=nextjs:nodejs /app/node_modules/yjs ./node_modules/yjs
128+
COPY --from=deps --chown=nextjs:nodejs /app/node_modules/y-protocols ./node_modules/y-protocols
129+
120130
# Copy the isolated-vm worker script
121131
COPY --from=builder --chown=nextjs:nodejs /app/apps/sim/lib/execution/isolated-vm-worker.cjs ./apps/sim/lib/execution/isolated-vm-worker.cjs
122132

0 commit comments

Comments
 (0)