Skip to content

fix(builder): materialize traced packages during standalone relocation - #194

Merged
antoinetoussaint-byte merged 1 commit into
mainfrom
fix/materialize-traced-packages-main
Oct 29, 2026
Merged

antoinetoussaint-byte merged 1 commit into
mainfrom
fix/materialize-traced-packages-main

Conversation

@antoinetoussaint-byte

Copy link
Copy Markdown
Contributor

Problem (measured on the Blue cell)

The saas frontend built by the released agent v0.0.170 fails at start, so every page answers 500:

Error: Failed to load external module require-in-the-middle-2ca7b9c2766f317e: Error: Cannot find module 'require-in-the-middle-2ca7b9c2766f317e'

Turbopack emits hashed package aliases for traced server dependencies (here Sentry's require-in-the-middle) as relative symlinks under .next/standalone/.next/node_modules/<name>-<hash> -> ../../node_modules/<name>. The standalone relocation in templates/builder/context/next-build.cjs.tmpl copied the standalone tree with fs.cpSync(..., { dereference: true }), which did not materialize that aliased package into the runtime, so the runtime image cannot resolve it once the build stage's source tree is gone.

Fix

Relocation copies with fs.promises.cp(..., { recursive: true, dereference: true }) for the standalone tree, public/static assets and export output, which materializes the traced alias as a real directory in the runtime. Cherry-picked from a3150419 alone (its parent was a dependabot gomod branch; that bump is not part of this PR, go.mod/go.sum are main's).

Classification: fix, at the owning place: the standalone relocation helper is this agent's build recipe. Reused: the existing helper and Node's fs.promises.cp; no new mechanism, no change to core or the CLI.

Tests

  • New opt-in TestNextTurbopackStandaloneRelocation (next_output_test.go): real next build (Next 16.4.1 + @sentry/nextjs 10.75.2, Turbopack), asserts the hashed require-in-the-middle-* alias exists, relocates it, withholds the source tree, starts node server.js from the runtime, requires GET /auth/callback = 200, and asserts the alias in the runtime is a materialized directory with identical bytes.
  • Locally (GOWORK=off, Node v24.22.1, Docker running):
    • go build ./..., go vet ./..., go mod tidy -diff: clean.
    • go test ./...: ok (131 PASS, 0 FAIL; TestNextjsLifecycle_Matrix native/nix/docker all ran and passed).
    • CODEFLY_TEST_NEXT_BUILD=1 go test -run '^TestNext(ConfiguredStandaloneOutput|ExportRejectsStaleOutput|TurbopackStandaloneRelocation)$': PASS (TurbopackStandaloneRelocation 24.6s: GET /auth/callback 200 with source withheld, alias require-in-the-middle-2ca7b9c2766f317e materialized; ConfiguredStandaloneOutput default + custom_nested; ExportRejectsStaleOutput default + custom).
    • Diagnosis check: with only the helper reverted to fs.cpSync, TestNextTurbopackStandaloneRelocation fails with expected: 200, actual: 500 and the server log shows the Blue error verbatim (Failed to load external module require-in-the-middle-2ca7b9c2766f317e ... Cannot find module). Same alias hash as Blue.

Not verified

  • Skipped as usual by go test ./...: TestCreateToRun (needs CODEFLY_TEST_RUNNER=1), TestManifestGuardRender (manifest-guard workflow), TestNativeAgentOwnershipLifecycle (needs built-artifact qualification env), TestSelectedConsumerBuildProjection (needs a consumer source). The ciinputs_conformance and proto_companion_required tagged suites were not run (the change does not touch discovery or Sync).
  • No image built by the CLI and run on a cell with this change yet; that follows the v0.0.171 release.

🤖 Generated with Claude Code

@antoinetoussaint-byte
antoinetoussaint-byte merged commit 42fa06b into main Oct 29, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant