Skip to content

Fix Next.js standalone images and build script detection - #167

Merged
kylemclaren merged 2 commits into
mainfrom
fix-nextjs-standalone
Oct 22, 2026
Merged

kylemclaren merged 2 commits into
mainfrom
fix-nextjs-standalone

Conversation

@kylemclaren

@kylemclaren kylemclaren commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #158 and #159.

Changes

  • standaloneNextjs now reads next.config.mjs, .js, .cjs, .ts and .mts. Before, it read only .mjs and .js. create-next-app makes next.config.ts by default.
  • nextjsGeneration is now false for standalone apps. The standalone image does not contain docker-entrypoint.js, the next CLI or the app sources, so the runtime generate step cannot run. Standalone apps now use npm run build, and they get no entrypoint.
  • nextjsGeneration now returns false when scripts.build does more than next build. next build followed only by flags (for example next build --turbopack) still uses the experimental build mode, as before. The old check (!this.#pj.scripts.build === 'next build') was always false, so custom build scripts such as next build && node scripts/postbuild.js were replaced with next build --experimental-build-mode compile.
  • The Next.js version check is now numeric. Before, it compared strings ('9.5' < '14.2' is false).

Tests

  • next-standalone: the expected Dockerfile now uses npm run build and has no ENTRYPOINT. The docker-entrypoint.js fixture is removed, because it is no longer generated.
  • New next-standalone-ts fixture: the same app with next.config.ts. It produces the same Dockerfile as next-standalone.
  • New next-custom-build fixture: Next.js 14.2.1 with "build": "next build && node scripts/postbuild.js". It produces RUN npm run build.
  • New next-build-flags fixture: Next.js 14.2.1 with "build": "next build --turbopack". It keeps next build --experimental-build-mode compile and the generation entrypoint.

Note: build scripts that run other commands, for example prisma generate && next build, now use the full npm run build at image build time instead of deferring prerender to the entrypoint.

With Next.js 16.4.2 apps, the generated images now build and start (HTTP 200): standalone with next.config.ts, standalone with next.config.mjs, and a custom build script (the postbuild step runs).

- Read next.config.ts, .mts and .cjs when checking for standalone
  output, not only .mjs and .js.
- Do not use experimental build mode for standalone apps. The
  standalone image does not contain docker-entrypoint.js, the next
  CLI or the sources, so the runtime generate step cannot run.
- Fix the scripts.build check in nextjsGeneration, which always
  passed, so custom build scripts were replaced.
- Compare the Next.js version numerically.

Fixes #158
Fixes #159
Treat `next build` followed only by flags (for example
`next build --turbopack`) as a plain Next.js build, so these apps keep
the deferred prerender step. Fall back to the app's build script only
when it does more than `next build`.
@kylemclaren
kylemclaren merged commit 63e82f1 into main Oct 22, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Next.js standalone: the container does not start

1 participant