Why do i get the "missing required width property" error when i'm loading static images?
Answered
Broken Nokia posted this in #help-forum
The documentation says that loading static assets from the public folder doesn't require you to specify height or width as it will be predetermined
15 Replies
@Broken Nokia The documentation says that loading static assets from the public folder doesn't require you to specify height or width as it will be predetermined
You need to either set the width & height of the image in the
height
and width
props or use fill
to let the image fill it. Keep in mind, when using fill
props on the image it will be automatically positioned absolute, so wrap your image in a relative containernoted, thank you
@Broken Nokia The documentation says that loading static assets from the public folder doesn't require you to specify height or width as it will be predetermined
no. only when you import the image statically would
width
and height
not be necessary. and thats what i'd recommend (and that doesnt require putting in the public folder). don't put the image in the public folder if you don't need toi specified the width, but it's still asking me to get the height
yes both width and height are required unless you import the image
import image from "./path/to/image.png"
@Broken Nokia i get a module not found error when i do this
how do you import it?
just put the image in the same folder and import it statically
Answer
@joulev just put the image in the same folder and import it statically
it felt like a very makeshift solution so i wanted to understand where i'm going wrong
but yes, this does work
but yes, this does work
@Broken Nokia it felt like a very makeshift solution so i wanted to understand where i'm going wrong
but yes, this does work
no it's not a makeshift solution, it is the officially recommended way to load local images https://nextjs.org/docs/app/building-your-application/optimizing/images#local-images
in a typical nextjs app, you only need to use the public folder for a small number of things. images, fonts and such need not be stored there
@joulev in a typical nextjs app, you only need to use the public folder for a small number of things. images, fonts and such need not be stored there
i see, i was under the impression that the logos would also be stored there
it's working now, thank you very much