Algobook
- The developer's handbook
mode-switch
back-button
Buy Me A Coffee
Sat Jun 10 2023

How to solve Next.js can't find the public folder

This will be a super short guide - but still helpful I hope. I will show what I was missing when I first built my Next.js application after I did our migration from a regular React app to Next.js, and caused that all my items in the /public folder was missing. Such as favicon and all my other icons and so on.

I was using Docker to build the application, and it was in my Dockerfile that the problem was.

Solution

The solution that I found, was very simple. I simply made the mistake to not copy it into my WORKDIR, which was /app in my case.

... WORKDIR /app ... COPY --from=builder /app/public ./public

And then, it worked as a charm. What the line is actually doing, is simple copying then /public folder into the working directory so that the built application can find it.

Summary

This was a super small post, but the idea and hope is that even these smaller posts can be helpful to you guys. And I will continue to post everytime I face these small annoying bugs and issues and hopefully help out.

Thanks for reading, and have a good one!

signatureSat Jun 10 2023
See all our articles