Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output Directory Content Deletion in Dev Mode #2865

Open
McSego1990 opened this issue Nov 9, 2024 · 0 comments
Open

Output Directory Content Deletion in Dev Mode #2865

McSego1990 opened this issue Nov 9, 2024 · 0 comments

Comments

@McSego1990
Copy link

Environment

Nitro Version: 2.10.4
Node Version: v20.18.0
Package Manager: [email protected]
Operating System: Linux

Reproduction

Steps to Reproduce

  1. Create a new Nuxt 3.14.x project (which uses Nitro 2.10.4)
  2. Run production build: pnpm build
  3. Verify output directory structure:
.output/
├── nitro.json
├── public/
│   ├── _nuxt/
│   ├── favicon.ico
│   └── robots.txt
└── server/
    ├── chunks/
    ├── index.mjs
    └── node_modules/
  1. Start development server: pnpm dev
  2. Observe output directory is minimized to:
.output/
├── public/
└── server/
    ├── index.mjs
    └── index.mjs.map

Expected Behavior

  • Production build output should remain intact when starting development server
  • Development server should not interfere with production build artifacts

Current Behavior

  • Starting development server deletes most of the production build output
  • Only minimal server files remain in the output directory

Workaround

We found a temporary workaround by separating development and production output directories:

{
  output: {
    dir: process.env.NODE_ENV === "development" ? ".output-dev" : ".output",
    serverDir: process.env.NODE_ENV === "development" 
      ? ".output-dev/server" 
      : ".output/server",
    publicDir: process.env.NODE_ENV === "development" 
      ? ".output-dev/public" 
      : ".output/public"
  }
}

Describe the bug

When using Nitro (via Nuxt 3.14.x), the production build output directory content is unexpectedly deleted or minimized when starting the development server. This issue was identified after observing the behavior in Nuxt 3.14.x and was traced back to Nitro's handling of the output directory.

However, this is suboptimal as:

  1. Development environment shouldn't need to affect production build output
  2. Creating a separate output directory for development seems unnecessary
  3. This behavior changed between Nitro versions (works correctly in older versions)

Technical Details

  • The issue seems related to Nitro's handling of the output directory during development mode
  • The problem appeared with Nuxt 3.14.x which uses Nitro 2.10.x
  • The issue does not occur with Nuxt 3.13.2 (older Nitro version)

Questions

  1. Is this an intended change in behavior?
  2. Is there a proper way to preserve production build output while running development server?
  3. Should we consider adding a configuration option to prevent development mode from cleaning production build files?

Additional context

No response

Logs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant