I was facing this issue in staging and production where I was building my application and it bugged me for quite a while because in development I could load my assets just fine.
Eventually, I realized that I was not copying my public folder into my docker container in staging and production. In development the public folder was there and could be served, but, as soon as I was serving my nestjs application from the dist folder, no dice.
The solution for me was to add a copy command to my Dockerfile:
COPY --chown=node:node --from=build /usr/local/app/public ./dist/public
and it was served thanks to:
app.useStaticAssets(join(__dirname, 'public'), {
index: false,
prefix: '/public/',
});
The docker command has some extra stuff for my specific build flow but just COPY /path/to/app/public ./dist/public
should work for you upon replacing path/to
with the correct path to your application code.