Next.js Discord

Discord Forum

Why do i get the "missing required width property" error when i'm loading static images?

Answered
Broken Nokia posted this in #help-forum
Open in Discord
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
Answered by joulev
just put the image in the same folder and import it statically
View full answer

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 container
noted, 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 to
i 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
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
it's working now, thank you very much