nitrojs / nitrojs/nitro

Output Directory Content Deletion in Dev Mode

Open
#2,865 1 comment 13 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug nuxt v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Environment
Nitro Version: 2.10.4
Node Version: v20.18.0
Package Manager: pnpm@9.12.3
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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with a Nuxt 3.14.x project using Nitro 2.10.4: run pnpm build, inspect .output/, then run pnpm dev and compare the contents. Trace Nitro's development-mode output-directory handling and verify that starting development preserves production artifacts without requiring separate directories.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, nuxt, typescript
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.