question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated image urls for files in the public directory result in 404's when running the built server.

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:13
  • Comments:19 (6 by maintainers)

github_iconTop GitHub Comments

15reactions
danielroecommented, Apr 13, 2022

You should see a PR handling this land this week ☺️

6reactions
Wharley01commented, Jan 12, 2022

I have temporary solution to this, change your images from <img src="/bla/bla.jpg"> to <img :src="'/bla/bla.jpg'">

Read more comments on GitHub >

github_iconTop Results From Across the Web

Django media-files get 404 even when files definitely exist
The problem I have is in a different code-part (and app), where I keep getting 404s although the generated url seems to match...
Read more >
Error 404: 4 Ways to Fix It - Hostinger
Error 404 is a response code, meaning the server could not locate the requested content. Check this article to learn 4 steps to...
Read more >
HTTP Status Codes, Network and DNS Errors, and Google ...
soft 404 errors. A soft 404 error is when a URL that returns a page telling the user that the page does not...
Read more >
How to handle loading of images that may not exist?
Handle it on your image server​​ Your image server knows if an image does not exist and sends a 404 Not Found HTTP...
Read more >
Error 404 not found - What does it mean & how to fix it! - IONOS
Reload the page: It might be that the error 404 has appeared for the simple reason that the page did not load properly....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found