nextbuild

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package nextbuild owns the `next build` invocation so the CLI can guarantee the build flags are correct for the chosen deployment target.

Why this exists: starting with Next 16, `next build` defaults to Turbopack. The Cloudflare Worker adapter (shared/nextcompile) scans `.next/server/app/*.js` and dynamic-imports each compiled page from a dispatch table — a model that fits Webpack's per-page CommonJS output but breaks on Turbopack's runtime-resolved chunks ("Dynamic require of 'path' is not supported"). Until the adapter is rewritten to use Next's standalone server.js as the entrypoint, we force Webpack for the Cloudflare target by passing `--webpack`.

AWS/VPS targets are unaffected — both runtime models work there because they ship the full standalone server, not a per-page dispatch.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsTurbopackOutput

func IsTurbopackOutput(standaloneDir string) bool

IsTurbopackOutput reports whether the given Next.js standalone tree was produced by Turbopack rather than Webpack.

Detection signal: Turbopack emits chunks named `[turbopack]_*.js` and `[root-of-the-server]__*._.js` under `.next/server/chunks/ssr/`. Webpack-mode standalone output never produces these filenames.

standaloneDir is the path to the extracted standalone tree (the directory containing server.js + .next/). For a not-yet-extracted build, point at the project root and the function will look at `.next/server/chunks/`.

Returns false (no error) when the tree doesn't exist — callers that need to distinguish "not built" from "built with Webpack" should stat the path themselves.

func Run

func Run(ctx context.Context, opts Opts) error

Run executes `next build` in opts.ProjectDir. The Next CLI is resolved from node_modules/.bin/next; if missing, falls back to `npx --yes next`.

stdout and stderr stream to the parent process unmodified — the build log is rich and operators rely on its line-by-line output.

Types

type Opts

type Opts struct {
	// ProjectDir is the working directory containing package.json and
	// next.config.*. Required.
	ProjectDir string

	// Target dictates the flag profile. Defaults to TargetGeneric.
	Target Target

	// Log receives lifecycle messages. May be nil; defaults to a noop.
	Log *shared.Logger

	// ExtraArgs is appended to the `next build` argv after target-specific
	// flags. Useful for callers that want to pass `--debug` or similar.
	ExtraArgs []string
}

Opts configures a single Run invocation.

type Target

type Target string

Target identifies which downstream packaging path the build feeds.

const (
	// TargetCloudflareWorker forces Webpack output (no Turbopack).
	TargetCloudflareWorker Target = "cloudflare-worker"
	// TargetAWSLambda runs a vanilla `next build`.
	TargetAWSLambda Target = "aws-lambda"
	// TargetVPS runs a vanilla `next build`.
	TargetVPS Target = "vps"
	// TargetGeneric runs a vanilla `next build`. Catch-all for callers
	// that haven't decided on a target yet.
	TargetGeneric Target = "generic"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL