I have a Next.js application that I deploy by running
next build
next start
on the server.
While the build is happening, it clears out the files in the .next build folder, so for a few seconds if I try to use the app, it will give an error because the files don't exist:
MissingStaticPage [Error]: Failed to load static file for page: /reporting/letter_exhibits ENOENT: no such file or directory, open '/home/polson/projects/JRP-Web-Tools/.next/server/pages/reporting/letter_exhibits.html'
Once I wait for the build to finish, the web app works as expected.
Is there a way to change the build process so that there will be no downtime during the build?
You can use this simple strategy, although it won't guarantee "zero" downtime, but it would be much better than the current experience. Basically, you build your project into a
tempfolder, and then delete existing.nextfolder, and rename yourtempfolder as.next.next.config.jsfile:You should probably use a process manager like pm2 for deployments though.