fix(docker): complete prod node_modules for the custom server
Follow-up to the NODE_PATH attempt, which fixed 'accepts' but not the general case: server-custom.js is CJS (esbuild --packages=external) and require()s deps the Next standalone trace ships ESM-only or omits, e.g. drizzle-orm/index.cjs (present-but-incomplete in the traced tree, so a NODE_PATH fallback can't rescue it). Replace the traced node_modules with the complete hoisted prod tree so every external resolves. That tree is prod-only, so move @next/bundle-analyzer (required at runtime by next.config — its import is unconditional even though enabled is gated on ANALYZE) from devDependencies to dependencies; otherwise the standalone config load throws MODULE_NOT_FOUND in prod. Validated end-to-end on a host prod install + standalone assembly: socket server boots, Socket.io initializes, HTTP listens, /api/health → 200, no MODULE_NOT_FOUND, no AsyncLocalStorage invariant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
30
Dockerfile
30
Dockerfile
@@ -41,21 +41,21 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|||||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
COPY --from=builder --chown=nextjs:nodejs /app/public ./public
|
||||||
COPY --from=builder --chown=nextjs:nodejs /app/dist/server.js ./server-custom.js
|
COPY --from=builder --chown=nextjs:nodejs /app/dist/server.js ./server-custom.js
|
||||||
# The custom socket.io server (server-custom.js, built with esbuild
|
# server-custom.js is CJS (esbuild --packages=external) and require()s its
|
||||||
# --packages=external) resolves socket.io and its FULL transitive closure
|
# deps at runtime — socket.io's full closure (engine.io→accepts/ws/cors),
|
||||||
# (engine.io → accepts/ws/cors, @socket.io/redis-adapter, ...) from
|
# drizzle-orm's CJS entry (index.cjs), zod, etc. The Next standalone trace
|
||||||
# node_modules at runtime. The Next tracer omits these from
|
# builds node_modules for the APP's ESM imports, so it omits the socket
|
||||||
# .next/standalone because no Next route imports the socket server
|
# server's deps entirely (MODULE_NOT_FOUND 'accepts') AND ships ESM-only
|
||||||
# (→ MODULE_NOT_FOUND 'accepts'). Stage the complete hoisted prod tree in
|
# entries for shared packages (drizzle-orm/index.cjs missing). A NODE_PATH
|
||||||
# a SEPARATE dir on NODE_PATH rather than touching the standalone
|
# fallback can't fix the latter — Node finds the incomplete package in the
|
||||||
# node_modules: overlaying real dirs onto its pnpm symlinks (e.g.
|
# standalone tree and errors instead of falling through. So replace the
|
||||||
# @react-pdf/renderer) fails the COPY, and replacing it wholesale swaps
|
# traced node_modules with the complete hoisted prod tree: every external
|
||||||
# out the standalone-tuned `next` and breaks Next's runtime
|
# the custom server requires resolves. Next's standalone .next runs fine
|
||||||
# (AsyncLocalStorage invariant). NODE_PATH is searched AFTER the local
|
# on the full `next` package (same version, superset of the trace); the
|
||||||
# walk, so Next still resolves its own deps from ./node_modules; only the
|
# one thing the standalone bootstrap would set — globalThis.AsyncLocalStorage
|
||||||
# socket server's otherwise-missing deps fall through to here.
|
# — is handled up-front by src/server-runtime-preamble.ts.
|
||||||
COPY --from=prod-deps --chown=nextjs:nodejs /app/node_modules ./_server_deps
|
RUN rm -rf ./node_modules
|
||||||
ENV NODE_PATH=/app/_server_deps
|
COPY --from=prod-deps --chown=nextjs:nodejs /app/node_modules ./node_modules
|
||||||
USER nextjs
|
USER nextjs
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
"@dnd-kit/utilities": "^3.2.2",
|
"@dnd-kit/utilities": "^3.2.2",
|
||||||
"@formkit/auto-animate": "^0.9.0",
|
"@formkit/auto-animate": "^0.9.0",
|
||||||
"@hookform/resolvers": "^5.2.2",
|
"@hookform/resolvers": "^5.2.2",
|
||||||
|
"@next/bundle-analyzer": "^16.2.6",
|
||||||
"@radix-ui/react-accordion": "^1.2.12",
|
"@radix-ui/react-accordion": "^1.2.12",
|
||||||
"@radix-ui/react-alert-dialog": "^1.1.15",
|
"@radix-ui/react-alert-dialog": "^1.1.15",
|
||||||
"@radix-ui/react-avatar": "^1.1.11",
|
"@radix-ui/react-avatar": "^1.1.11",
|
||||||
@@ -140,7 +141,6 @@
|
|||||||
"@axe-core/playwright": "^4.11.3",
|
"@axe-core/playwright": "^4.11.3",
|
||||||
"@faker-js/faker": "^10.4.0",
|
"@faker-js/faker": "^10.4.0",
|
||||||
"@hookform/devtools": "^4.4.0",
|
"@hookform/devtools": "^4.4.0",
|
||||||
"@next/bundle-analyzer": "^16.2.6",
|
|
||||||
"@playwright/test": "^1.60.0",
|
"@playwright/test": "^1.60.0",
|
||||||
"@tailwindcss/postcss": "^4.3.0",
|
"@tailwindcss/postcss": "^4.3.0",
|
||||||
"@total-typescript/ts-reset": "^0.6.1",
|
"@total-typescript/ts-reset": "^0.6.1",
|
||||||
|
|||||||
6
pnpm-lock.yaml
generated
6
pnpm-lock.yaml
generated
@@ -28,6 +28,9 @@ importers:
|
|||||||
'@hookform/resolvers':
|
'@hookform/resolvers':
|
||||||
specifier: ^5.2.2
|
specifier: ^5.2.2
|
||||||
version: 5.2.2(react-hook-form@7.75.0(react@19.2.6))
|
version: 5.2.2(react-hook-form@7.75.0(react@19.2.6))
|
||||||
|
'@next/bundle-analyzer':
|
||||||
|
specifier: ^16.2.6
|
||||||
|
version: 16.2.6
|
||||||
'@radix-ui/react-accordion':
|
'@radix-ui/react-accordion':
|
||||||
specifier: ^1.2.12
|
specifier: ^1.2.12
|
||||||
version: 1.2.12(@types/react-dom@19.2.3(@types/react@19.2.14))(@types/react@19.2.14)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)
|
version: 1.2.12(@types/react-dom@19.2.3(@types/react@19.2.14))(@types/react@19.2.14)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)
|
||||||
@@ -332,9 +335,6 @@ importers:
|
|||||||
'@hookform/devtools':
|
'@hookform/devtools':
|
||||||
specifier: ^4.4.0
|
specifier: ^4.4.0
|
||||||
version: 4.4.0(@types/react@19.2.14)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)
|
version: 4.4.0(@types/react@19.2.14)(react-dom@19.2.6(react@19.2.6))(react@19.2.6)
|
||||||
'@next/bundle-analyzer':
|
|
||||||
specifier: ^16.2.6
|
|
||||||
version: 16.2.6
|
|
||||||
'@playwright/test':
|
'@playwright/test':
|
||||||
specifier: ^1.60.0
|
specifier: ^1.60.0
|
||||||
version: 1.60.0
|
version: 1.60.0
|
||||||
|
|||||||
Reference in New Issue
Block a user