fix: detect Turbopack builds and set TURBOPACK env accordingly #1056
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.
Summary
Fixes runtime errors when deploying Next.js 16 apps built with Turbopack to AWS Lambda.
Problem
When building with Turbopack (default in Next.js 16), the standalone output only includes
*-turbo.runtime.prod.jsfiles (e.g.,pages-turbo.runtime.prod.js), not the webpack variants (pages.runtime.prod.js).The previous behavior unconditionally set
TURBOPACK=falseinmodule.compiled.js, which caused it to try loading non-existent runtime files at runtime:Solution
This PR detects whether the build was done with Turbopack by checking the traced files:
*-turbo.runtime.prod.jsfiles exist → Turbopack build → setTURBOPACK=trueTURBOPACK=falseTesting
Tested with a Next.js 16.0.7 app built with Turbopack and deployed to AWS Lambda via SST. Before the fix: 502 errors. After the fix: 200 OK.