Repository navigation
Fix Next.js standalone images and build script detection - #167
Merged
Merged
Conversation
- 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`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #158 and #159.
Changes
standaloneNextjsnow readsnext.config.mjs,.js,.cjs,.tsand.mts. Before, it read only.mjsand.js.create-next-appmakesnext.config.tsby default.nextjsGenerationis now false for standalone apps. The standalone image does not containdocker-entrypoint.js, thenextCLI or the app sources, so the runtimegeneratestep cannot run. Standalone apps now usenpm run build, and they get no entrypoint.nextjsGenerationnow returns false whenscripts.builddoes more thannext build.next buildfollowed only by flags (for examplenext 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 asnext build && node scripts/postbuild.jswere replaced withnext build --experimental-build-mode compile.'9.5' < '14.2'is false).Tests
next-standalone: the expected Dockerfile now usesnpm run buildand has noENTRYPOINT. Thedocker-entrypoint.jsfixture is removed, because it is no longer generated.next-standalone-tsfixture: the same app withnext.config.ts. It produces the same Dockerfile asnext-standalone.next-custom-buildfixture: Next.js 14.2.1 with"build": "next build && node scripts/postbuild.js". It producesRUN npm run build.next-build-flagsfixture: Next.js 14.2.1 with"build": "next build --turbopack". It keepsnext build --experimental-build-mode compileand the generation entrypoint.Note: build scripts that run other commands, for example
prisma generate && next build, now use the fullnpm run buildat 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 withnext.config.mjs, and a custom build script (the postbuild step runs).