nuxt: Generated image urls for files in the public directory result in 404's when running the built server.
Environment
Local:
- Operating System:
Darwin - Node Version:
v17.0.1 - Nuxt Version:
3.0.0-27303148.ac98373 - Package Manager:
yarn@1.22.10 - Bundler:
Vite - User Config:
publicRuntimeConfig,meta - Runtime Modules:
- - Build Modules:
-
Remote (Slightly older version of nuxt but still has the same problem):
- Operating System:
Linux - Node Version:
v17.0.1 - Nuxt Version:
3.0.0-27294839.7e5e50b - Package Manager:
yarn@1.22.15 - Bundler:
Vite - User Config:
publicRuntimeConfig,meta - Runtime Modules:
- - Build Modules:
-
Reproduction
When running the dev server images work fine: https://codesandbox.io/s/nuxt-3-missing-images-dev-2xj0y
However when running the nuxi build command and then running (node) .output/server/index.mjs all images result in 404s: https://codesandbox.io/s/nuxt-3-missing-images-prod-rvge4
Describe the bug
When building the server all images urls that reference a file in the public directory get parsed and prefixed with /_nuxt/.
So this code (referring to the file /project/public/images/my-logo.jpg):
<img href="/images/my-logo.jpg" />
Will be turned into:
<img href="/_nuxt/images/my-logo.jpg" />
It seems ever since version 3.0.0-27296423.f3082ca these urls have resulted in 404’s when running the built server. (The images work fine when running the local development server as this doesn’t prefix the urls)
Additional context
Might be related to:
Personally I find it a little ulgy-looking that the urls of the files I put in my public directory get prefixed with /_nuxt/. I would instead expect only my compiled js and css to be prefixed like that. Although that’s just personal preference to be fair.
Logs
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19