nuxt / nuxt/image

[v2.0.0] Custom image dir duplicated to public output during generate (ipx/ipxStatic)

Open
#2,040 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
1.5k
Forks
331
Avg merge
19h 52m
Merged PRs (30d)
9

Description

Describe the bug
When using @nuxt/image v2 with a custom dir configuration (e.g., assets/media), the entire source directory is automatically copied to the .output/public folder during nuxt generate / prerendering.

This happens with both ipx and ipxStatic providers.

It appears that v2.0.0 automatically registers the configured dir into Nitro's publicAssets list. This forces Nitro to copy the raw source files to the distribution folder, resulting in build bloat and exposing source assets that should remain internal.

Environment

  • OS: Windows 10 (WSL / Ubuntu 24.04)
  • Node: v23.10
  • Package Manager: pnpm 10.19.0
  • Nuxt: v4.2.1
  • @nuxt/image: v2.0.0

Reproduction

  1. Initialize a fresh Nuxt project.
  2. Create a source directory: assets/media and place a large image file inside.
  3. Configure nuxt.config.ts:
export default defineNuxtConfig({
  modules: ['@nuxt/image'],
  image: {
    dir: 'assets/media',
    provider: 'ipxStatic' // Reproducible with 'ipx' as well
  }
})
  1. Run pnpm run generate.
  2. Inspect the .output/public directory.

Expected behavior
The output directory should only contain the optimized _ipx folder (and generated app files). The raw source folder (assets/media) should NOT be copied to the public output.

Actual behavior
The output directory contains both:

  1. The optimized images in _ipx/
  2. The contents of the source directory are copied to the root of the public output directory (e.g., source assets/media/folder/img.jpg becomes .output/public/folder/img.jpg).

Workaround
A nitro:init hook can be used to manually filter out the source directory from Nitro's public assets list before the build starts.

export default defineNuxtConfig({
  hooks: {
    'nitro:init'(nitro) {
      nitro.options.publicAssets = nitro.options.publicAssets.filter(
        (asset) => !asset.dir?.includes('assets/media')
      )
    }
  }
})

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

Start with the nuxt.config.ts reproduction and run pnpm run generate using ipxStatic, then compare the .output/public contents with the expected _ipx output. Trace how image.dir reaches Nitro's publicAssets during generation for both ipx and ipxStatic; done means the raw assets/media files are no longer copied while optimized images still generate.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.