mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 04:22:01 +00:00
It's been long enough I think we can change these to refer to `@vercel/next` instead. x-ref: [slack thread](https://vercel.slack.com/archives/C03DQ3QFV7C/p1674849801196389)
2.1 KiB
2.1 KiB
@vercel/next Legacy Mode
Why This Warning Occurred
@vercel/next has two modes: legacy and serverless. You will always want to use the serverless mode. legacy is to provide backwards compatibility with previous @vercel/next versions.
The differences:
Legacy:
- Minimal lambda size of
2.2Mb(approximately) - Forces
next@v7.0.2-canary.49andnext-server@v7.0.2-canary.49 - Forces all
dependenciesto bedevDependencies - Loads
next.config.json bootup, breaking sometimes when users didn't usephasesto load files - Used
next-serverwhich is the full Next.js server with routing etc. - Runs
npm install - Runs
npm run now-build - Runs
npm install --productionafter build
Serverless:
- Minimal lambda size of
49Kb(approximately) - Uses Next.js build targets (
target: 'serverless') innext.config.js. documentation - Does not make changes to your application dependencies
- Does not load
next.config.js(as per the serverless target documentation) - Runs
npm install - Runs
npm run now-build - Does not run
npm install --productionas the output from the build is all that's needed to bundle lambdas. - No runtime dependencies, meaning smaller lambda functions
- Optimized for fast cold start
Possible Ways to Fix It
In order to create the smallest possible lambdas Next.js has to be configured to build for the serverless target.
- Serverless Next.js requires Next.js 8 or later, to upgrade you can install the
latestversion:
npm install next --save
- Add the
now-buildscript to yourpackage.json
{
"scripts": {
"now-build": "next build"
}
}
- Add
target: 'serverless'tonext.config.js
module.exports = {
target: 'serverless',
// Other options are still valid
};
- Optionally make sure the
"src"in"builds"points to your applicationpackage.json
{
"version": 2,
"builds": [{ "src": "package.json", "use": "@vercel/next" }]
}