Build on the server, locally or in a container: Next.js and AdonisJS
Where should an application be built before it runs on a server? Until now, Catapult answered with two families of recipes: nextjs and adonisjs built on the server, while nextjs_local and adonisjs_local built on your machine and uploaded the result.
Both answers have a cost. Building on the server needs the package manager, the dev dependencies and enough memory for the build, on a machine that should mostly serve traffic. Building locally avoids that, but your machine is rarely the server: node_modules installed on macOS, or on another architecture, contain native modules that will not load on Linux. The classic symptom is a Next.js app whose image route returns a 500 because sharp was built for Darwin.
The nextjs and adonisjs recipes now take a single setting for this: build.location.
Three locations
set('build', { location: 'container' })| Location | Where it builds | What the server needs |
|---|---|---|
remote (default) | In the release, on the server | Node.js and the package manager |
local | On your machine | Node.js |
container | In a Node.js container of the server platform | Node.js |
remote keeps the existing behavior: nothing changes for current deployments.
local builds on your machine and sends a ready-to-run release. It is fast and fine as long as your dependencies have no native code, or when the machine that deploys matches the server, such as a Linux CI runner of the same architecture (see CI/CD).
container is the new option. Catapult reads the Node.js version of the server, then builds in node:<major>-bookworm for the server architecture, linux/arm64 for example. Native modules are compiled for the platform and the Node.js version that will run them. Your own node_modules and build output are not touched, and the npm cache is kept in a volume, so later builds are quick. Docker or Podman is required on your machine, nothing more on the server.
Next.js
With local and container, the recipe builds the standalone output, copies .next/static, public and an optional ecosystem.config.cjs next to server.js, and uploads it as the release. The server runs no install and no build:
// deploy.ts
import { defineConfig, set } from '@catapultjs/deploy'
import '@catapultjs/deploy/recipes/nextjs'
import '@catapultjs/deploy/recipes/pm2'
set('build', { location: 'container' })
export default defineConfig({
hosts: [{ name: 'production', ssh: 'deploy@example.com', deployPath: '/srv/web' }],
})Run the server from the release root: script: 'server.js' with PM2, or ExecStart=/usr/bin/node server.js with systemd.
AdonisJS
For AdonisJS, local and container go one step further: after node ace build, they install the production dependencies in build/, on your machine or in the container. The server receives a ready-to-run build/ and never runs the package manager:
// deploy.ts
import { defineConfig, set } from '@catapultjs/deploy'
import '@catapultjs/deploy/recipes/adonisjs'
import '@catapultjs/deploy/recipes/pm2'
set('build', { location: 'container' })
export default defineConfig({
hosts: [{ name: 'production', ssh: 'deploy@example.com', deployPath: '/srv/api' }],
})This is a change from adonisjs_local, which installed the production dependencies on the server. Migrations run from the release as before, whatever the location.
Custom tasks in the build container
With build.location: 'container', attach custom tasks before or after deploy:build. Use container(command) in a TypeScript task or a container step in JSON to generate files before the build or package the output before Catapult uploads it. See the Container builds guide for a JSON example.
Checking the Node.js version first
AdonisJS 7 requires Node.js 24. A server still running Node.js 22 used to fail late, at build or at startup. Before building, both recipes compare the server’s Node.js version with the engines.node requirements they can find. They read the project’s requirement from package.json and look for the framework’s requirement in package-lock.json or the installed package:
@adonisjs/core requires Node.js >=24.0.0, the server runs 22.22.1The check runs in every location, remote included.
Faster uploads
Build outputs with dependencies contain thousands of small files. Catapult now sends a directory as one compressed tar stream over SSH instead of a recursive scp. In our tests, a production node_modules of about 3,700 files went 2 to 3 times faster on a local network, and the gap grows with latency. Symbolic links such as node_modules/.bin are kept as links. This applies to every recipe that uploads a directory, including the default deploy:update_code.
What about the _local recipes?
recipes/nextjs_local and recipes/adonisjs_local are deprecated. They keep working, with the same pipeline, as aliases of the main recipes with build: { location: 'local' }, and print a warning. adonisjs_local still installs the production dependencies on the server. To migrate, import the main recipe and set the location:
// before
import '@catapultjs/deploy/recipes/nextjs_local'
// after
import '@catapultjs/deploy/recipes/nextjs'
set('build', { location: 'local' }) // or 'container'The same build setting drives the new Laravel Go and Laravel Rust recipes, covered in the next article. See the Next.js and AdonisJS recipe pages for all options.