Next.js Discord

Discord Forum

next build doesn't copy all images in the public/ folder to the build #65024

Unanswered
New Guinea Freshwater Crocodile posted this in #help-forum
Open in Discord
New Guinea Freshwater CrocodileOP
I have an image that I am importing in one of my components dynamically like so:
const img = new Image();
img.src = 'img.png';

And the image is in the public/ folder.
Now, I know that Next.js uses the Image component that comes bundled in Next.js, but that component doesn't work with canvas, so I need to load images like this.

The problem is that when I run next build, next doesn't pick up that I need this image statically and doesn't bundle it with the rest of the build files. Even if it did, the path is now changed to '/_next/static/media/img.png' instead. Is there an easy fix for this? Or should I submit a feature request/bug report?

0 Replies