serverless-next.js: TimeoutError: Connection timed out after 120000ms

Describe the bug When I run serverless command, after something like ~6 minutes, I get the following error: TimeoutError: Connection timed out after 120000ms

api-lambda folder size is 189MB default-lambda folder size is 100MB

To Reproduce I just run serverless.

Expected behavior Deployed successfully.

Screenshots image

Desktop (please complete the following information):

  • OS: Windows
  • Version 10

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 25 (3 by maintainers)

Most upvoted comments

Yup, no worries. For completeness sake, I forgot to mention you can also minimize your Next.js build outputs using something like this in next.config.js. It can be used instead of useServerlessTraceTarget. This is what I use for production since I use the regular serverless target: it makes the build take longer but my Lambda ZIP is ~20% smaller. Only caveat is by minimizing perhaps it’ll make it harder to debug if you don’t have useful error messaging or logging, as you can’t refer to line number in source code.

(Use terser-webpack-plugin)

  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    if (isServer && !dev && process.env.NEXT_MINIMIZE === "true") {
      config.optimization = {
        minimize: true,
        minimizer: [
          new TerserPlugin({
            parallel: true,
            cache: true,
            terserOptions: {
              output: { comments: false },
              mangle: true,
              compress: true,
            },
            extractComments: false,
          }),
        ],
      };
    }

    return config;
  }

I’ll close the issue for now and work on improving the docs/code in the near future.