Deploy a Next.js standalone build to a 1 GB VPS without building on the server
A Next.js standalone frontend still fits a 1 GB VPS if the build moves to your local machine: ship the image over SSH and fix the deploy order so the API is up before the build.
TL;DR
A Next.js standalone frontend can live on a 1 GB VPS without a server-side build: build the image locally and ship it via docker save over SSH. Two blockers broke the build along the way, an npm 10 lockfile rejection and prerender fetching the API during build. The right deploy order makes the same build pass in one run.
Two error lines in one afternoon. The first came out of npm ci inside the build container: Missing: @swc/[email protected] from lock file. The second appeared when the build was almost done: the /sitemaps/index.xml route failed prerendering with FetcherError: 404 Not Found. Both happened while I was moving a blog frontend to a 1 GB class VPS, and both had different root causes.
Quick context. The frontend had lived for a long time on a hosting platform that handles builds automatically. The plan was to move it to our own VPS so builds and costs stay under control. The VPS is small: free -h showed 964 MB total RAM with 273 MB free after the other stack on that box was running. That number immediately closed one option: building Next.js on the server is the fastest way to make the OOM killer earn its name.
Ship the image, don’t build on the VPS
The standalone output from Next.js produces a light server bundle, but the next build process itself is still heavy. So the order flips: build the full image on the local machine, then ship the finished result to the VPS.
docker build -f frontend/Dockerfile.prod \
--build-arg NEXT_PUBLIC_API_URL="https://api.example.com/api" \
-t myapp-fe:20261204 frontend/
docker save myapp-fe:20261204 | gzip -1 \
| ssh [email protected] 'gunzip | docker load'
The final image was 181 MB of content, shipped in one command with no intermediate registry. On the VPS, the container only needs to join the same docker network as the already-running nginx, and a new vhost points at it. The RAM it uses sits far below the number that would let a build survive.
npm 10’s lockfile validator rejects an npm 11 lock
The npm ci failure earlier was not a corrupted lockfile. The local machine runs npm 11, and the lockfile it produces is canonical for that version. The build container used node:22-alpine, which ships npm 10, and the npm ci validator in that version rejected the same structure with the "missing from lock file" message. npm ci is designed to run only when package.json and the lockfile are perfectly in sync, so a version-based rejection like this is documented behavior, not a bug.
The fix is one line: raise the build base image to node:24-alpine, which carries npm 11, matching the local machine. To stop guessing in the future, validate before running docker build:
cd frontend && npm ci --dry-run --no-audit --no-fund
A zero exit code from that command means the lockfile will pass npm ci inside the container. Failing at this stage is cheap; failing in the middle of next build burns build time that was already spent.
Prerender fetches the API at build time, so bring the API up first
The second failure was sneakier. Once the lockfile was settled, the build ran all the way to generating static pages, then stopped at /sitemaps/index.xml with a 404. The sitemap route in this application fetches the public API during the build. As it happened, the endpoint it fetches had just moved its route on the server, and the old gateway still answered 404.
Which means deploy order decides the outcome. Because the NEXT_PUBLIC_API_URL value is baked into the bundle at build time, the API being fetched must already be alive and routed correctly before next build runs. After the API route was fixed and confirmed answering 200, the same build succeeded without any additional changes. The frontend landed on the VPS, the nginx vhost pointed at its container, and the blog rendered content from the API just like before.
One decision came out of this experience: the deploy order is now written down explicitly. API first, frontend second, and the npm ci --dry-run check goes in before the docker build line. Those two afternoon failures became a short, cheap checklist for the next deploy.
Tested on Docker Engine 29 (local) and 28 (VPS), Node 24 alpine, npm 11.19.1, Next.js 16, December 2026.
Sources: [1] Next.js docs, output: standalone includes the server bundle, copy .next/static and public manually, accessed 2026-12-04 [2] npm ci docs: only runs when package.json and the lockfile are in sync, accessed 2026-12-04 [3] Docker docs, docker image save: stream an image to an archive for loading on another host, accessed 2026-12-04