Next.js Discord

Discord Forum

NextJS Image not working when deployed

Unanswered
Danna posted this in #help-forum
Open in Discord
Works fine in the development enviroment, but when deployed to firebase hosting - it shows up like this and doesn't render

136 Replies

the code
      <Image
        alt="a basil leaf"
        className="object-scale-down absolute md:w-4/12  w-11/12 md:rotate-0 rotate-[51deg] md:-top-1/3 -top-[17%] md:-left-20 -left-[10%] drop-shadow-img"
        src="/resources/basil.png"
        fill
      />
What shows up in the build
<img alt="a basil leaf" loading="lazy" decoding="async" data-nimg="fill" class="object-scale-down absolute md:w-4/12  w-11/12 md:rotate-0 rotate-[51deg] md:-top-1/3 -top-[17%] md:-left-20 -left-[10%] drop-shadow-img" style="position:absolute;height:100%;width:100%;left:0;top:0;right:0;bottom:0;color:transparent" sizes="100vw" srcset="/_next/image?url=%2Fresources%2Fbasil.png&amp;w=640&amp;q=75 640w, /_next/image?url=%2Fresources%2Fbasil.png&amp;w=750&amp;q=75 750w, /_next/image?url=%2Fresources%2Fbasil.png&amp;w=828&amp;q=75 828w, /_next/image?url=%2Fresources%2Fbasil.png&amp;w=1080&amp;q=75 1080w, /_next/image?url=%2Fresources%2Fbasil.png&amp;w=1200&amp;q=75 1200w, /_next/image?url=%2Fresources%2Fbasil.png&amp;w=1920&amp;q=75 1920w, /_next/image?url=%2Fresources%2Fbasil.png&amp;w=2048&amp;q=75 2048w, /_next/image?url=%2Fresources%2Fbasil.png&amp;w=3840&amp;q=75 3840w" src="/_next/image?url=%2Fresources%2Fbasil.png&amp;w=3840&amp;q=75">
would it be better to not have my images in the /public/resources/ folder?
(would it change anything if I removed /resources/ ?
I've found a github issue about the topic
but it's from 2020 . without a clear resolution.

any help would be great
@Danna but it's from 2020 . without a clear resolution. any help would be great
have you tried importing the image with an import statement as in

import Basil from "/resources/basil.png" and then <Image src={Basil} .../>
yep! sadly changes nothing
here's another thread detailling the issue
no idea if an "official" solution has been found tho... I'm not sure if using a workaround is better than simply using a normal <img> tag
because the <img> on its own works fine
@Dayo have you tried importing the image with an `import` statement as in `import Basil from "/resources/basil.png" and then <Image src={Basil} .../> `
what do you think about this?
@Dayo any errs in your console? any deployment errs?
well, I only get the 404 error once it's deployed to firebase hosting.

it's exactly what's described in the github issue
the image loads just fine on localhost
website link btw
right now my images are too slow and performance is rather awful so my plan is to convert everything to the nextJS Image component
but things just arent working out 😅
@Danna https://makeithealthy-dce64.firebaseapp.com/
weird. taking a closer look
what version of Next are you using?
    "next": "13.4.4",
@Danna what do you think about this?
I think I'll just try this and see how it goes
...
can you try deploying to say Vercel to see if it's strictly a Firebase issue
uh, sure. I'll have to check how to deploy to vercel first but I'll try
I'll ping you once it's done
but you have several other images on the website. does it mean those aren't in the public folder?
okay
ffs
before you try Vercel, try moving the image to a different folder. maybe src/assets/images and see if it works
yeah no, it doesn't like that at all

import googlePlayBadge from "../../imageTest/gplayBadge.png";
do you not have alias imports?
@DirtyCajunRice | AppDir do you not have alias imports?
huh, what would that change?
oh. i just read into that. that's actually really neat. didn't know about those
but it theoretically shouldn't change anything, no?
trying it with vercel right now ...
@Danna but it theoretically shouldn't change anything, no?
compilers are fickle things 🙂
you dont have a custom image loader anymore correct?
if you dont remove that its hard to have a control group
@DirtyCajunRice | AppDir you dont have a custom image loader anymore correct?
no, I don't have a custom image loader
also keep in mind you dont have any static image width/height
if it doesnt render this time, add width/height to the image. If it renders that time its because you are using fill and the wrapping div has no static size
this is to avoid CLS
I've tried with width / height and with fill. makes no difference sadly
Since you did the import?
which one ? 😅
@/resources/googlethingy.png
since you alias imported it
oh, I haven't tried it with the alias import specifically. give me a minute
do it all at once
just to rule it all out
alias import + w + h + (make sure you committed the image to your repo)
i know the last one is dumb but rather say it 😂
@DirtyCajunRice | AppDir alias import + w + h + (make sure you committed the image to your repo)
the way it's set up right now
that warning doesnt have anything to do with your image tho
that warning is - i would assume - from improper theme class usage
hmm
interesting
well, the image doesn't show up either way 🤔
well yeah. Whats inspect show?
the image folder sits at /src/images/ right now by the way
@DirtyCajunRice | AppDir well yeah. Whats inspect show?
<img alt="Google Play Badge" loading="lazy" width="180" height="37" decoding="async" data-nimg="1" class="drop-shadow-img" style="" srcset="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2FgplayBadge.0354ac69.png&amp;w=256&amp;q=75 1x, /_next/image?url=%2F_next%2Fstatic%2Fmedia%2FgplayBadge.0354ac69.png&amp;w=384&amp;q=75 2x" src="/_next/image?url=%2F_next%2Fstatic%2Fmedia%2FgplayBadge.0354ac69.png&amp;w=384&amp;q=75">
this is on localhost in dev mode
@Danna the image folder sits at /src/images/ right now by the way
and your alias import is aliased to @/src/*
?
@DirtyCajunRice | AppDir and your alias import is aliased to @/src/*
    "paths": {
      "@/*": ["./src/*"],
      "@/images/": ["./src/images"]
    }
what in the
the second line is redundant
remove that
oh true, just realized 🤦‍♂️
but still doesn't change a thing
baby steps 😛
😅
so it errors on dev now?
as in doesnt show the image
yeah, if imported via alias from /src/images/ it won't show.

The only way to get the images showing on dev is if I import them from the public folder
then you have next config messed up
because you absolutely do not need to have them in public
 
/** @type {import('next').NextConfig} */
const nextConfig = {

};

module.exports = nextConfig;
that's my next config tho 😅
and next version?
"next": "13.4.4",
and app dir?
yep
Can you screenshot your folders?
I could give you access to the github repo if that helps
are you using next/image directly
or that random Image.js file
yeah, import Image from "next/image";
@DirtyCajunRice | AppDir or that random Image.js file
that's just something I've tried but removed again
but I believe that won't work with app directory
i have hundreds of images this way. So i am sure its not a bug
I have no idea how to move on honestly
another silly question: you have restarted dev server correct?
yeah 👍
oh my god 🤦‍♂️
the import works
when copying the images files to the /images/ folder
the image somehow got corrupted or whatever
XD
I copied it in there again
and it now loads
in the dev mode on localhost at least. now to try on firebase
... firebase?
firebase hosting!
i know what it is
just cant help if you are doing some static export thing
thats a whole other can of worms
ah, gotcha.

if firebase really is the problem ... i gues vercel is where I'll deploy for now?
I just used firebase because of its ease of use
yeah, sadly still won't show on firebase 🤦‍♂️
@DirtyCajunRice | AppDir just cant help if you are doing some static export thing
also, I don't believe it's really a static export on there. it uses the new firebase fullstack thing. but I'll probably save myself some headache moving away
but id bet the farm that it works
god dammit
that is config lol
any other errors?
pretty much only this and it complaining about the bare img tags
it will full error if your eslint tells it to
escape your apostrophies lol
🙂
i officially hate firebase
👍