Skip to content

Standalone app crashes on every route on Vercel/Netlify: circular import TDZ between @agent-native/core and @agent-native/creative-context #2752

Description

@Nate-Lassiter

Summary

A standalone content template app (single app, not a workspace) crashes on every request when deployed to Vercel or Netlify with NITRO_PRESET=vercel / NITRO_PRESET=netlify:

ReferenceError: Cannot access 'Ml' before initialization
    at U (file:///var/task/_libs/@agent-native/core+[...].mjs:103:19158)
    at file:///var/task/_libs/@agent-native/creative-context+[...].mjs:2:305
    at ModuleJob.run (node:internal/modules/esm/module_job:343:25)

(The mangled variable name changes per build/minify pass — e.g. Ml, Zpe, Dl — but the call path is identical every time: @agent-native/creative-context's bundled chunk imports @agent-native/core's bundled chunk, which throws a temporal-dead-zone ReferenceError at top-level evaluation.)

This reproduces on both Vercel and Netlify, so it isn't platform-specific — it's the shared standalone build path both presets go through.

Repro

npx @agent-native/core@latest create my-app --standalone --template content
cd my-app
pnpm install
NITRO_PRESET=vercel pnpm build   # or NITRO_PRESET=netlify
# deploy the output (vercel deploy --prebuilt, or netlify deploy --build)
# visit any route

Every route returns FUNCTION_INVOCATION_FAILED (Vercel) / "This function has crashed" (Netlify).

What I've ruled out

  • Not a version issue. Reproduces identically on @agent-native/core@0.133.3 (pinned) and @agent-native/core@0.146.1 (latest at time of testing) — same call path, only the minified variable name differs.
  • Not the known workspace-deploy bug (Workspace deploy --preset vercel: every route 500s (cachedHandler is not a function -> e.headers.get is not a function) #2324). That issue's fix (patchVercelFunctionEntry in workspace-deploy.ts) only applies to multi-app agent-native deploy --preset vercel workspace deploys. A standalone app built via agent-native build (which calls into build.ts, not workspace-deploy.ts) never goes through that code path, so the fix is irrelevant here.
  • Not fixable by disabling minification. Patching build.ts's createNitro({ minify: true }) to false locally avoids the TDZ crash but trips a different guard: assertSingleTemplateNetlifyBuildOutput rejects the build with "Netlify server bundle leaves ingestion dependencies as runtime imports: officeparser" — so minification and the per-package chunk-splitting strategy are entangled, and turning one off breaks the other check.
  • Not a missing documented step. Followed the deployment docs exactly: NITRO_PRESET=vercel npx @agent-native/core@latest build (or the Vite plugin nitro.preset option) is the sanctioned build-time preset switch, and that's what was used.

Suspected root cause

build.ts's nitroNoExternalsForPreset() sets noExternals: [] for the netlify, vercel, and aws-lambda presets, causing Nitro's Rolldown pipeline to bundle every npm dependency into its own combined per-package chunk file (_libs/@agent-native/core+[...].mjs, _libs/@agent-native/creative-context+[...].mjs, etc.) instead of leaving them as regular node_modules imports. @agent-native/core and @agent-native/creative-context appear to have a circular import between them at the module level; when each package is isolated into its own chunk file, the evaluation order Rolldown picks for that split violates the TDZ for a const/let binding, crashing at cold start on every single route (not just ones touching creative-context features directly — even the app root crashes).

This same noExternals: [] treatment is shared by netlify/vercel/aws-lambda, which is consistent with the crash reproducing on both Vercel and Netlify but (presumably) not on the default node preset, which uses a much smaller externals allowlist (NITRO_SERVER_RUNTIME_BUNDLED_DEPS) instead of bundling everything.

Environment

  • @agent-native/core: reproduced on 0.133.3 and 0.146.1
  • nitro: 3.0.260610-beta
  • Template: content (standalone shape)
  • Tested serverless targets: Vercel (Node runtime, vercel deploy --prebuilt), Netlify (Functions v2, netlify deploy --build)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions