This repository has been archived by the owner on Jan 28, 2025. It is now read-only.
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.
Problem
Next.js "serverless" target creates one bundle per SSR page in your application. The bundle contains everything the page needs for it to be server side rendered in Lambda. The problem with this is it leads to a lot of duplicated code / dependencies across page bundles. I started a discussion on this a while back on the Next repo: vercel/next.js#10456.
This is particularly an issue for applications with a large number of server side rendered pages that need deploying to Lambda (@edge or not), where the artefact size limit set by AWS is 250MB (uncompressed).
Solution
Next.js core team recently introduced a new target:
experimental-serverless-trace
which rather than bundling all dependencies / node_modules into each page bundle, it marks node_modules asexternals
in webpack thus creating thin serverless wrappers around the pages. This is also the target being used by the Now platform since next 9.0.4.With this PR serverless-next.js will copy the dependencies of the next pages into the lambda artefacts, using @zeit/node-file-trace to track down which files are needed, same as
now-next
builder does.This change will be non breaking, the "serverless" target will continue to be used for a while but that may change in future.
To benefit from the new target, make sure when you are running
$ serverless
to deploy, yournext.config.js
is set to:Even though is prefixed with
experimental-
it is the target the Now platform is using behind the scenes so it should be safe forserverless-next.js
to use.Related issues: #236