Skip to content

Make sure next picks up the correct config file when called by nextjs_standalone_build()#2778

Draft
MatrixFrog wants to merge 1 commit intoaspect-build:mainfrom
MatrixFrog:tyler/next-fix
Draft

Make sure next picks up the correct config file when called by nextjs_standalone_build()#2778
MatrixFrog wants to merge 1 commit intoaspect-build:mainfrom
MatrixFrog:tyler/next-fix

Conversation

@MatrixFrog
Copy link

@MatrixFrog MatrixFrog commented Mar 19, 2026

Without this change, there are two next config files available to the next binary: the one the user passed in, and next.bazel.mjs, which has been renamed to next.config.mjs by copy_file(). We want it to use the next.bazel.mjs one as the config file, but if the one from the user is named next.config.js, then it gets picked up by the next CLI instead.

By renaming the user's config (prefixing it with __original), we ensure that next will pick up the one we want it to.

Changes are visible to end-users: yes

  • Searched for relevant documentation and updated as needed: I don't think there is any docs update needed
  • Breaking change (forces users to change their own code or config): I suppose it could be, if someone was inadvertently depending on the current behavior, but it seems unlikely.
  • Suggested release notes appear below: no

Test plan

[TODO: need to add a test where the config file that's passed in is named next.config.js and should maybe do a next.config.ts one too]

  • Covered by existing test cases
  • New test cases added
  • Manual testing; please provide instructions so we can reproduce:

@aspect-workflows
Copy link

aspect-workflows bot commented Mar 19, 2026

Bazel 7 (Test)

All tests were cache hits

317 tests (100.0%) were fully cached saving 42s.


Bazel 8 (Test)

All tests were cache hits

275 tests (100.0%) were fully cached saving 35s.


Bazel 9 (Test)

All tests were cache hits

275 tests (100.0%) were fully cached saving 39s.


Bazel 7 (Test)

e2e/bzlmod

All tests were cache hits

7 tests (100.0%) were fully cached saving 664ms.


Bazel 8 (Test)

e2e/bzlmod

All tests were cache hits

7 tests (100.0%) were fully cached saving 642ms.


Bazel 9 (Test)

e2e/bzlmod

All tests were cache hits

7 tests (100.0%) were fully cached saving 596ms.


Bazel 7 (Test)

e2e/git_dep_metadata

All tests were cache hits

1 test (100.0%) was fully cached saving 30ms.


Bazel 8 (Test)

e2e/git_dep_metadata

All tests were cache hits

1 test (100.0%) was fully cached saving 26ms.


Bazel 9 (Test)

e2e/git_dep_metadata

All tests were cache hits

1 test (100.0%) was fully cached saving 30ms.


Bazel 7 (Test)

e2e/gyp_no_install_script

All tests were cache hits

2 tests (100.0%) were fully cached saving 112ms.


Bazel 8 (Test)

e2e/gyp_no_install_script

All tests were cache hits

1 test (100.0%) was fully cached saving 50ms.


Bazel 9 (Test)

e2e/gyp_no_install_script

All tests were cache hits

1 test (100.0%) was fully cached saving 46ms.


Bazel 7 (Test)

e2e/js_binary_workspace

All tests were cache hits

1 test (100.0%) was fully cached saving 44ms.


Bazel 8 (Test)

e2e/js_binary_workspace

All tests were cache hits

1 test (100.0%) was fully cached saving 30ms.


Bazel 9 (Test)

e2e/js_binary_workspace

All tests were cache hits

1 test (100.0%) was fully cached saving 35ms.


Bazel 7 (Test)

e2e/js_image_oci

All tests were cache hits

1 test (100.0%) was fully cached saving 3s.


Bazel 7 (Test)

e2e/npm_link_package

All tests were cache hits

2 tests (100.0%) were fully cached saving 172ms.


Bazel 8 (Test)

e2e/npm_link_package

All tests were cache hits

2 tests (100.0%) were fully cached saving 137ms.


Bazel 9 (Test)

e2e/npm_link_package

All tests were cache hits

2 tests (100.0%) were fully cached saving 170ms.


Bazel 7 (Test)

e2e/npm_link_package-esm

All tests were cache hits

2 tests (100.0%) were fully cached saving 189ms.


Bazel 8 (Test)

e2e/npm_link_package-esm

All tests were cache hits

2 tests (100.0%) were fully cached saving 138ms.


Bazel 9 (Test)

e2e/npm_link_package-esm

All tests were cache hits

2 tests (100.0%) were fully cached saving 173ms.


Bazel 7 (Test)

e2e/npm_link_package-rerooted

All tests were cache hits

2 tests (100.0%) were fully cached saving 207ms.


Bazel 8 (Test)

e2e/npm_link_package-rerooted

All tests were cache hits

2 tests (100.0%) were fully cached saving 139ms.


Bazel 9 (Test)

e2e/npm_link_package-rerooted

All tests were cache hits

2 tests (100.0%) were fully cached saving 186ms.


Bazel 7 (Test)

e2e/npm_translate_lock

All tests were cache hits

3 tests (100.0%) were fully cached saving 383ms.


Bazel 8 (Test)

e2e/npm_translate_lock

All tests were cache hits

3 tests (100.0%) were fully cached saving 287ms.


Bazel 9 (Test)

e2e/npm_translate_lock

All tests were cache hits

3 tests (100.0%) were fully cached saving 289ms.


Bazel 7 (Test)

e2e/npm_translate_lock_disable_hooks

All tests were cache hits

3 tests (100.0%) were fully cached saving 268ms.


Bazel 8 (Test)

e2e/npm_translate_lock_disable_hooks

All tests were cache hits

1 test (100.0%) was fully cached saving 62ms.


Bazel 9 (Test)

e2e/npm_translate_lock_disable_hooks

All tests were cache hits

1 test (100.0%) was fully cached saving 32ms.


Bazel 7 (Test)

e2e/npm_translate_lock_empty

All tests were cache hits

2 tests (100.0%) were fully cached saving 132ms.


Bazel 8 (Test)

e2e/npm_translate_lock_empty

All tests were cache hits

2 tests (100.0%) were fully cached saving 114ms.


Bazel 9 (Test)

e2e/npm_translate_lock_empty

All tests were cache hits

2 tests (100.0%) were fully cached saving 105ms.


Bazel 7 (Test)

e2e/npm_translate_lock_exclude_package_contents

All tests were cache hits

1 test (100.0%) was fully cached saving 33ms.


Bazel 8 (Test)

e2e/npm_translate_lock_exclude_package_contents

All tests were cache hits

1 test (100.0%) was fully cached saving 21ms.


Bazel 9 (Test)

e2e/npm_translate_lock_exclude_package_contents

All tests were cache hits

1 test (100.0%) was fully cached saving 86ms.


Bazel 7 (Test)

e2e/npm_translate_lock_multi

All tests were cache hits

2 tests (100.0%) were fully cached saving 106ms.


Bazel 8 (Test)

e2e/npm_translate_lock_multi

All tests were cache hits

2 tests (100.0%) were fully cached saving 54ms.


Bazel 9 (Test)

e2e/npm_translate_lock_multi

All tests were cache hits

2 tests (100.0%) were fully cached saving 113ms.


Bazel 7 (Test)

e2e/npm_translate_lock_partial_clone

All tests were cache hits

1 test (100.0%) was fully cached saving 26ms.


Bazel 8 (Test)

e2e/npm_translate_lock_partial_clone

All tests were cache hits

1 test (100.0%) was fully cached saving 30ms.


Bazel 9 (Test)

e2e/npm_translate_lock_partial_clone

All tests were cache hits

1 test (100.0%) was fully cached saving 38ms.


Bazel 7 (Test)

e2e/npm_translate_lock_replace_packages

All tests were cache hits

4 tests (100.0%) were fully cached saving 321ms.


Bazel 8 (Test)

e2e/npm_translate_lock_replace_packages

All tests were cache hits

4 tests (100.0%) were fully cached saving 249ms.


Bazel 9 (Test)

e2e/npm_translate_lock_replace_packages

All tests were cache hits

4 tests (100.0%) were fully cached saving 320ms.


Bazel 7 (Test)

e2e/npm_translate_lock_subdir_patch

All tests were cache hits

1 test (100.0%) was fully cached saving 50ms.


Bazel 8 (Test)

e2e/npm_translate_lock_subdir_patch

All tests were cache hits

1 test (100.0%) was fully cached saving 67ms.


Bazel 9 (Test)

e2e/npm_translate_lock_subdir_patch

All tests were cache hits

1 test (100.0%) was fully cached saving 50ms.


Bazel 7 (Test)

e2e/npm_translate_package_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 25ms.


Bazel 8 (Test)

e2e/npm_translate_package_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 62ms.


Bazel 9 (Test)

e2e/npm_translate_package_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 32ms.


Bazel 7 (Test)

e2e/npm_translate_yarn_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 25ms.


Bazel 8 (Test)

e2e/npm_translate_yarn_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 62ms.


Bazel 9 (Test)

e2e/npm_translate_yarn_lock

All tests were cache hits

1 test (100.0%) was fully cached saving 32ms.


Bazel 7 (Test)

e2e/output_paths

All tests were cache hits

2 tests (100.0%) were fully cached saving 213ms.


Bazel 8 (Test)

e2e/output_paths

All tests were cache hits

2 tests (100.0%) were fully cached saving 252ms.


Bazel 9 (Test)

e2e/output_paths

All tests were cache hits

2 tests (100.0%) were fully cached saving 171ms.


Bazel 7 (Test)

e2e/package_json_module

All tests were cache hits

1 test (100.0%) was fully cached saving 195ms.


Bazel 8 (Test)

e2e/package_json_module

Buildkite build #12417 is running...


Bazel 9 (Test)

e2e/package_json_module

All tests were cache hits

1 test (100.0%) was fully cached saving 190ms.


Bazel 7 (Test)

e2e/patch_from_repo

All tests were cache hits

1 test (100.0%) was fully cached saving 25ms.


Bazel 7 (Test)

e2e/pnpm_lockfiles

All tests were cache hits

41 tests (100.0%) were fully cached saving 4s.


Bazel 8 (Test)

e2e/pnpm_lockfiles

All tests were cache hits

13 tests (100.0%) were fully cached saving 1s.


Bazel 9 (Test)

e2e/pnpm_lockfiles

All tests were cache hits

13 tests (100.0%) were fully cached saving 955ms.


Bazel 7 (Test)

e2e/pnpm_repo_install

All tests were cache hits

1 test (100.0%) was fully cached saving 746ms.


Bazel 8 (Test)

e2e/pnpm_repo_install

All tests were cache hits

1 test (100.0%) was fully cached saving 772ms.


Bazel 9 (Test)

e2e/pnpm_repo_install

All tests were cache hits

1 test (100.0%) was fully cached saving 738ms.


Bazel 7 (Test)

e2e/pnpm_version

All tests were cache hits

1 test (100.0%) was fully cached saving 44ms.


Bazel 8 (Test)

e2e/pnpm_version

All tests were cache hits

1 test (100.0%) was fully cached saving 44ms.


Bazel 9 (Test)

e2e/pnpm_version

All tests were cache hits

1 test (100.0%) was fully cached saving 42ms.


Bazel 7 (Test)

e2e/pnpm_workspace

All tests were cache hits

15 tests (100.0%) were fully cached saving 2s.


Bazel 8 (Test)

e2e/pnpm_workspace

All tests were cache hits

14 tests (100.0%) were fully cached saving 2s.


Bazel 9 (Test)

e2e/pnpm_workspace

All tests were cache hits

14 tests (100.0%) were fully cached saving 2s.


Bazel 7 (Test)

e2e/pnpm_workspace_deps

All tests were cache hits

3 tests (100.0%) were fully cached saving 212ms.


Bazel 8 (Test)

e2e/pnpm_workspace_deps

All tests were cache hits

3 tests (100.0%) were fully cached saving 278ms.


Bazel 9 (Test)

e2e/pnpm_workspace_deps

All tests were cache hits

3 tests (100.0%) were fully cached saving 237ms.


Bazel 7 (Test)

e2e/pnpm_workspace_rerooted

All tests were cache hits

15 tests (100.0%) were fully cached saving 2s.


Bazel 8 (Test)

e2e/pnpm_workspace_rerooted

All tests were cache hits

14 tests (100.0%) were fully cached saving 1s.


Bazel 9 (Test)

e2e/pnpm_workspace_rerooted

All tests were cache hits

14 tests (100.0%) were fully cached saving 2s.


Bazel 7 (Test)

e2e/repo_mapping

All tests were cache hits

3 tests (100.0%) were fully cached saving 222ms.


Bazel 8 (Test)

e2e/repo_mapping

All tests were cache hits

3 tests (100.0%) were fully cached saving 154ms.


Bazel 9 (Test)

e2e/repo_mapping

All tests were cache hits

3 tests (100.0%) were fully cached saving 308ms.


Bazel 7 (Test)

e2e/runfiles

All tests were cache hits

6 tests (100.0%) were fully cached saving 660ms.


Bazel 8 (Test)

e2e/runfiles

All tests were cache hits

6 tests (100.0%) were fully cached saving 693ms.


Bazel 9 (Test)

e2e/runfiles

All tests were cache hits

6 tests (100.0%) were fully cached saving 921ms.


Bazel 7 (Test)

e2e/stamped_package_json

All tests were cache hits

1 test (100.0%) was fully cached saving 48ms.


Bazel 8 (Test)

e2e/stamped_package_json

All tests were cache hits

1 test (100.0%) was fully cached saving 24ms.


Bazel 9 (Test)

e2e/stamped_package_json

All tests were cache hits

1 test (100.0%) was fully cached saving 130ms.


Bazel 7 (Test)

e2e/vendored_node

All tests were cache hits

1 test (100.0%) was fully cached saving 61ms.


Bazel 8 (Test)

e2e/vendored_node

All tests were cache hits

1 test (100.0%) was fully cached saving 57ms.


Bazel 9 (Test)

e2e/vendored_node

All tests were cache hits

1 test (100.0%) was fully cached saving 57ms.


Bazel 7 (Test)

e2e/vendored_tarfile

All tests were cache hits

1 test (100.0%) was fully cached saving 25ms.


Bazel 8 (Test)

e2e/vendored_tarfile

All tests were cache hits

1 test (100.0%) was fully cached saving 62ms.


Bazel 9 (Test)

e2e/vendored_tarfile

All tests were cache hits

1 test (100.0%) was fully cached saving 32ms.


Bazel 7 (Test)

e2e/verify_patches

All tests were cache hits

2 tests (100.0%) were fully cached saving 92ms.


Bazel 8 (Test)

e2e/verify_patches

All tests were cache hits

2 tests (100.0%) were fully cached saving 120ms.


Bazel 9 (Test)

e2e/verify_patches

All tests were cache hits

2 tests (100.0%) were fully cached saving 120ms.


Bazel 7 (Test)

e2e/worker

All tests were cache hits

1 test (100.0%) was fully cached saving 75ms.


Bazel 8 (Test)

e2e/worker

All tests were cache hits

1 test (100.0%) was fully cached saving 50ms.


Bazel 9 (Test)

e2e/worker

All tests were cache hits

1 test (100.0%) was fully cached saving 92ms.


Bazel 7 (Test)

examples/proto

All tests were cache hits

1 test (100.0%) was fully cached saving 120ms.


Bazel 8 (Test)

examples/proto

All tests were cache hits

1 test (100.0%) was fully cached saving 132ms.


Bazel 9 (Test)

examples/proto

All tests were cache hits

1 test (100.0%) was fully cached saving 116ms.


Buildifier      Format

@MatrixFrog MatrixFrog changed the title Fix for Zipline issue Fix for nextjs config file issue Mar 19, 2026
@MatrixFrog MatrixFrog changed the title Fix for nextjs config file issue Make sure next picks up the correct config file when called by nextjs_standalone_build() Mar 20, 2026

copy_file(
name = "_%s.original_config_file" % name,
src = config,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if config is also in data via js_library(srcs)? Then it might still end up in the runfiles|bindir and the bug might still occur?

That makes me wonder if we should instead just disallow nextjs_*build(config) from using the standard names. It would be a breaking change, but the entire change can just be an if config-is-standard-name: fail() at the top of the macro....

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so. What name would be recommended instead?

Alternatively, can we detect if the same file appears in both config and data, and fail() if it does?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't truly detect what is in data when we're in a macro, it would have to be within a rule that launches an action with data as input or maybe does data.to_list() to convert depset()s to a list that can be inspected. All things I wouldn't want to do.

We could maybe just do:

write_file(out = "next.config.js", content = "throw new Error(...)")

then if the user also has a file of that same name they will get a bazel error saying "conflicting file outputs" - however that will be a generic bazel error and the user won't understand it. That might be good to do regardless actually, just to be 100% sure, while also doing the if path.basename(config) == "next.config.js": fail("nicer error message)...?

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.

2 participants