🌐 AI搜索 & 代理 主页
Skip to content

Conversation

@Flo0806
Copy link
Collaborator

@Flo0806 Flo0806 commented Nov 27, 2025

🔗 Linked issue

Resolves: #33733

📚 Description

Fixes .output being created in layer subdirectory instead of project root when layers use ESM configs (.mjs, .js with "type": "module", or from node_modules).

The bug occurred because layer.config.rootDir ??= layer.cwd! directly mutated the cached ESM module object. On subsequent builds, the cached object already had rootDir set to the layer's directory.

Fix: Create a shallow copy via spread operator instead of mutating the original.

@Flo0806 Flo0806 requested a review from danielroe as a code owner November 27, 2025 22:25
@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@coderabbitai
Copy link

coderabbitai bot commented Nov 27, 2025

Walkthrough

The change modifies the layer configuration handling in the loader config module to prevent mutation of cached layer configuration objects. It introduces a resolved root directory value that defaults to the layer config's existing rootDir or falls back to layer.cwd. The layer configuration is then rewritten as a shallow copy with the resolved rootDir applied. Additionally, the processed-layers tracking mechanism is updated to use this resolved rootDir value instead of the original layer.config.rootDir, which prevents duplicate processing when rootDir was previously undefined.

Possibly related PRs

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: avoiding mutation of cached ESM config objects in layer resolution to fix the .output directory issue.
Description check ✅ Passed The description clearly explains the bug, root cause, and fix related to ESM config mutation in layer resolution, matching the changeset objectives.
Linked Issues check ✅ Passed The code changes directly address issue #33733 by preventing mutation of cached ESM config objects through creating a shallow copy, ensuring .output is generated in the correct directory.
Out of Scope Changes check ✅ Passed All changes in packages/kit/src/loader/config.ts are focused on fixing the ESM config mutation bug; no unrelated modifications are present.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81356f8 and 60476d4.

📒 Files selected for processing (1)
  • packages/kit/src/loader/config.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,vue}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Follow standard TypeScript conventions and best practices

Files:

  • packages/kit/src/loader/config.ts
**/*.{ts,tsx,js,jsx,vue}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{ts,tsx,js,jsx,vue}: Use clear, descriptive variable and function names
Add comments only to explain complex logic or non-obvious implementations
Keep functions focused and manageable (generally under 50 lines), and extract complex logic into separate domain-specific files
Remove code that is not used or needed
Use error handling patterns consistently

Files:

  • packages/kit/src/loader/config.ts
🧠 Learnings (1)
📚 Learning: 2024-11-05T15:22:54.759Z
Learnt from: GalacticHypernova
Repo: nuxt/nuxt PR: 26468
File: packages/nuxt/src/components/plugins/loader.ts:24-24
Timestamp: 2024-11-05T15:22:54.759Z
Learning: In `packages/nuxt/src/components/plugins/loader.ts`, the references to `resolve` and `distDir` are legacy code from before Nuxt used the new unplugin VFS and will be removed.

Applied to files:

  • packages/kit/src/loader/config.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: codeql (javascript-typescript)
  • GitHub Check: code
  • GitHub Check: semantic-pr
🔇 Additional comments (2)
packages/kit/src/loader/config.ts (2)

83-88: Excellent fix for the ESM cache mutation issue.

The solution correctly prevents mutation of cached ESM config objects by creating a shallow copy before assigning rootDir. The approach is sound:

  • resolvedRootDir explicitly captures the intended value before modification
  • The spread operator creates a new object, leaving the cached module untouched
  • Gracefully handles undefined layer.config with the fallback to an empty object

This directly addresses the root cause described in issue #33733 where subsequent builds incorrectly placed .output in layer subdirectories.


91-92: Consistent tracking logic with the resolved value.

Updating the duplicate layer detection to use resolvedRootDir maintains consistency with the new approach and avoids any dependency on the potentially mutated config object. The logic remains functionally equivalent whilst being more explicit about the value being tracked.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 27, 2025

Open in StackBlitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@33779

@nuxt/nitro-server

npm i https://pkg.pr.new/@nuxt/nitro-server@33779

nuxt

npm i https://pkg.pr.new/nuxt@33779

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@33779

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@33779

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@33779

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@33779

commit: 60476d4

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 27, 2025

CodSpeed Performance Report

Merging #33779 will not alter performance

Comparing Flo0806:fix/layer-esm-cache-mutation (60476d4) with main (81356f8)

Summary

✅ 10 untouched

@danielroe danielroe merged commit 42ff3df into nuxt:main Dec 9, 2025
54 of 56 checks passed
@github-actions github-actions bot mentioned this pull request Dec 9, 2025
@github-actions github-actions bot mentioned this pull request Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prod build is built in layer folder instead of root dir when layer config is loaded via ESM

2 participants