image.dir option in nuxt.config.ts results in 404 on production
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.5k
- Forks
- 331
- Avg merge
- 19h 52m
- Merged PRs (30d)
- 9
Description
Hey all!
We were running into some issues where we implemented this module and suddenly our build does break and the images cannot be displayed. The browser gets a 404 when requesting the images. In production we are running nuxt inside a docker containter.
While trying to reproduce this issue with a clean repo i discovered that the image.dir option (docs) is resulting in this behavior.
Versions:
@nuxt/image: 1.3.0
nuxt: 3.10.1
node: v20.4.0
I also tried your playground, same problem. See the playground fork here: https://stackblitz.com/edit/github-fxrrqo-tfd5wv
So clean repo with:
npx nuxi@latest init nuxt-image-testnpm install @nuxt/image- Added
@nuxt/imageto modules in nuxt.config.ts - Add Image (e.g.
TestPhoto.webp) withNuxtImg-Tag toapp.vue - Set src-attribute to
src="/TestPhoto.webp" - Run
npm run devand see working site - Run
npm run buildandnpm run previewto see correct site
So add image.dir as module options:
- Add
dir: "public/img" - Move Image to a new folder
public/img - Set src of
NuxtImg-Tag tosrc="TestPhoto.webp" - Run
npm run devand see working site - Run
npm run buildandnpm run previewto see broken site
While discovering this, I removed the image.dir option in our project and the production build does not fail anymore.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce this in a clean Nuxt project using @nuxt/image 1.3.0: configure image.dir as public/img, move TestPhoto.webp there, then compare npm run dev with npm run build and npm run preview. Use the linked playground fork as an additional reproduction. Done means the configured image path works in the production preview without a 404.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- nuxt, typescript
- Domain
- frontend, web-dev
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100