Serverless environments are sensitive to bundle size, since it has to download and unzip the contents. To help reduce cold start times as much as possible, you should remove any unnecessary files in the node_modules or report offending dev libraries in this PR (opens in a new tab)
Next 14+ no longer includes dev dependencies like @swc, esbuild, etc... in the output node_modules, so please upgrade at your earliest convenience.
To identify the module that's taking up too much space (and isn't serverless friendly):
du -hs .open-next/server-function/node_modules/* | sort -rh
If your app requires the offending library, then consider moving your business logic of the
api to its own lambda, eg:
There is a PR (opens in a new tab) to remove some dev dependency from the output node_modules but that requires more testing before it can merge.
sharp is not needed outside of the
Image Optimization function so you should not have it as a dependency. But if you are depending on
sharp, be sure to install it with the correct flags for your lambda.
--arch=arm64 --platform=linux --target=18 --libc=glibc
If you need to use pdfjs, you should install it with
npm i pdfjs-dist--no-optionalbecause the optional dep:
canvastakes about 180MB.
If the above doesn't work (or gives some compilation errors) you can try:
Please open an issue or let us know on discord if there are any other modules that are causing issues.