Running nx build myNextJsApp creates build artifacts including assets from /public folder.
Running nx build myNextJsApp and next start loads the app but assets are not in the built folder.
UPDATE:
TLDR: copy /public folder to dist/apps/myApp when running nx build myApp.
It would also be helpful to have artifacts in a .next folder in dist/apps/myApp when building. This makes it more simple to deploy.
DETAILS:
I misunderstood how mapping to /public folder works.
I assumed that /public folder would be copied in .next folder (making assets part of the build artifacts).
Instead these are simply referenced, by this I mean that the minimum structure of your project to be deployed on a hosting platform/server is:
root
This is somehow different from usual webpack configuration I'm aware of but reduces build time, I guess.
A plain next app wouldn/t worry about this since next build command creates a new .next folder in the same root folder.
The command nx build myApp does not copy /public folder to dist/apps/myApp as it should.
I come from a Google search. I got the same issue with my monorepo + Next.JS. The nx will run the command in the app's folder, so it will search all the public assets under apps/your_app/public/**/*.
Basically, to fix this temporary you need to move your public assets to your application folder.
Yup. Basically move assets from apps/myNextJsApp/public to dist/apps/myNextJsApp/public.
I think that only nx export actually moves the assets correctly.
Yes. Unless next.js support merge different public assets. Another hack solution right now would be you can manually move the assets from one place to another. You can find the right buildId in the BUILD_ID file.
Just ran into this issue as well.
I just ran into this today as well.
Could this be fixed by adding the copy-webpack-plugin to the nx build builder, to copy apps/<project-name>/public to dist/apps/<project-name>/public ?
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nrwl community! 馃檹
This is still an issue AFAICT
Sorry. The issue was marked by mistake. I removed the label.
This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 馃檹
The assets are now copied from app/[name]/public to dist/apps/[name]/public and should be served correctly now.
Most helpful comment
Sorry. The issue was marked by mistake. I removed the label.