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 ¶
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.
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" )