fix(nextjs): match standalone server copy patterns to build output la…#2887
Merged
acozzette merged 1 commit intoJun 15, 2026
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 534e9fa080
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
534e9fa to
e3da294
Compare
Contributor
|
@imanmalekian31 Thank you for this fix and the detailed description! Would you be ok with signing the CLA? |
Contributor
Author
|
@acozzette Thanks, I've signed it. |
acozzette
approved these changes
Jun 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix
nextjs_standalone_serverproducing ajs_binarythat fails at runtime becauseserver.jsis never copied into the assembled standalone directory.Symptom
An OCI image (or
bazel run) built fromnextjs_standalone_build+nextjs_standalone_serverfails to start:The build succeeds — the failure only appears at runtime, because the server's
js_binaryentry point points at aserver.jsthat was never assembled into the standalone output.Root cause
nextjs_standalone_server's internalcopy_to_directoryusesinclude_srcs_patterns/replace_prefixesprefixed with.next/:But the
apptree (thenextjs_standalone_buildoutput) does not expose its files under a.next/prefix.nextjs_standalone_buildrunsnext build(which writes to.next) and then copies that tree into a directory named after the build target via_copy_exec_to_bin— it cannot reuse.next, since that path is already owned by the build action. So a build target:fooyields paths likefoo/standalone/...andfoo/static/....Since
copy_to_directorymatches paths relative to the package (defaultroot_paths = ["."]), the.next/-prefixed patterns match nothing — onlypublic/**is copied.server.jsand.next/staticnever make it into the standalone directory, and the binary dies at runtime.Empirically confirmed (build target named
next, packagedisplayads/panel/frontend):.next/standalone/**→ matches nothingstandalone/**→ matches nothingnext/standalone/**→ matches (the prefix is the build target's directory name)This is a regression from #2879, which flattened the
.nextwrapper innextjs_standalone_build's output layout without updatingnextjs_standalone_server's patterns to match.Fix
Derive the prefix from the
applabel (app.split(":")[-1].split("/")[-1]) and use it ininclude_srcs_patterns/replace_prefixesinstead of the hardcoded.next, matching the actual flattened layout. This mirrors the existing label-parsing the macro already does for the config basename, and is independent of the Next.js version.Reproduction
nextjs_standalone_build(name = "next", ...)thennextjs_standalone_server(name = "next_server", app = ":next").bazel build //path:_next_server.standalone.public/is present; noserver.js, no.next/static.js_binary→entry_point ... server.js not found.Changes are visible to end-users: yes
Test plan
nextjs_standalone_build(name = "next", ...)+nextjs_standalone_server(name = "next_server", app = ":next").bazel build //path:_next_server.standaloneand inspect the output —standalone/<pkg>/server.jsandstandalone/<pkg>/.next/staticare now present.bazel run //path:next_serverstarts successfully instead of failing with the missing-entry-point error.