Function deploy fails because 50mb limited reached even so the function deployed is only 25kb

Hi,

I having issues deploying a nestjs application. Apparently it is over 50mb but looking at the build, the function deployed is only 23kb but I am still getting this error. I am running out of ideas. Please help.

[build]
    command = "nx run api:build:production"
    publish = "apps/api/site/index.html"
    functions = "dist/apps/api"
10:29:47 AM: build-image version: f0de447600c93198b2eef6ed4ec8e338d9c0582c (focal)
10:29:47 AM: buildbot version: f0de447600c93198b2eef6ed4ec8e338d9c0582c
10:29:47 AM: Fetching cached dependencies
10:29:47 AM: Starting to download cache of 396.2MB
10:29:50 AM: Finished downloading cache in 2.727s
10:29:50 AM: Starting to extract cache
10:29:51 AM: Finished extracting cache in 815ms
10:29:51 AM: Finished fetching cache in 3.606s
10:29:51 AM: Starting to prepare the repo for build
10:29:51 AM: Preparing Git Reference refs/heads/main
10:29:52 AM: Parsing package.json dependencies
10:29:53 AM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'dist/apps/api' versus 'dist/apps/api/' in the Netlify UI
10:29:53 AM: Starting to install dependencies
10:29:54 AM: Started restoring cached Node.js version
10:29:54 AM: Finished restoring cached Node.js version
10:29:54 AM: Attempting Node.js version 'v16.13.0' from .nvmrc
10:29:54 AM: v16.13.0 is already installed.
10:29:55 AM: Now using node v16.13.0 (npm v8.1.0)
10:29:55 AM: Enabling Node.js Corepack
10:29:55 AM: Started restoring cached build plugins
10:29:55 AM: Finished restoring cached build plugins
10:29:55 AM: Started restoring cached corepack dependencies
10:29:55 AM: Finished restoring cached corepack dependencies
10:29:55 AM: No npm workspaces detected
10:29:55 AM: Started restoring cached node modules
10:29:55 AM: Finished restoring cached node modules
10:29:55 AM: Installing npm packages using npm version 8.1.0
10:30:12 AM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
10:30:13 AM: npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
10:30:14 AM: npm WARN deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated
10:30:14 AM: npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
10:30:17 AM: npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
10:30:17 AM: npm WARN deprecated multiaddr-to-uri@6.0.0: This module is deprecated, please upgrade to @multiformats/multiaddr-to-uri
10:30:17 AM: npm WARN deprecated mkdirp-promise@5.0.1: This package is broken and no longer maintained. 'mkdirp' itself supports promises now, please switch to that.
10:30:18 AM: npm WARN deprecated multibase@4.0.6: This module has been superseded by the multiformats module
10:30:18 AM: npm WARN deprecated multiaddr@8.1.2: This module is deprecated, please upgrade to @multiformats/multiaddr
10:30:19 AM: npm WARN deprecated ipld-raw@6.0.0: This module has been superseded by the multiformats module
10:30:19 AM: npm WARN deprecated multicodec@3.2.1: This module has been superseded by the multiformats module
10:30:19 AM: npm WARN deprecated har-validator@5.1.5: this library is no longer supported
10:30:20 AM: npm WARN deprecated superagent@6.1.0: Please upgrade to v7.0.2+ of superagent.  We have fixed numerous issues with streams, form-data, attach(), filesystem errors not bubbling up (ENOENT on attach()), and all tests are now passing.  See the releases tab for more information at <https://github.com/visionmedia/superagent/releases>.
10:30:20 AM: npm WARN deprecated formidable@1.2.6: Please upgrade to latest, formidable@v2 or formidable@v3! Check these notes: https://bit.ly/2ZEqIau
10:30:20 AM: npm WARN deprecated ipld-dag-cbor@0.17.1: This module has been superseded by @ipld/dag-cbor and multiformats
10:30:21 AM: npm WARN deprecated ipld-dag-pb@0.20.0: This module has been superseded by @ipld/dag-pb and multiformats
10:30:22 AM: npm WARN deprecated cids@1.1.9: This module has been superseded by the multiformats module
10:30:23 AM: npm WARN deprecated apollo-server-types@3.8.0: The `apollo-server-types` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023). This package's functionality is now found in the `@apollo/server` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details.npm WARN deprecated apollo-server-errors@3.3.1: The `apollo-server-errors` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023). This package's functionality is now found in the `@apollo/server` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details.npm WARN deprecated apollo-server-plugin-base@3.7.2: The `apollo-server-plugin-base` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023). This package's functionality is now found in the `@apollo/server` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details.npm WARN deprecated apollo-datasource@3.3.2: The `apollo-datasource` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023). See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details.
10:30:27 AM: npm WARN deprecated apollo-server-lambda@3.12.0: The `apollo-server-lambda` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023). This package's functionality is now found in the `@apollo/server` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details.npm WARN deprecated apollo-server-express@3.12.0: The `apollo-server-express` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023). This package's functionality is now found in the `@apollo/server` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details.npm WARN deprecated @walletconnect/types@1.8.0: WalletConnect's v1 SDKs are now deprecated. Please upgrade to a v2 SDK. For details see: https://docs.walletconnect.com/npm WARN deprecated apollo-server-env@4.2.1: The `apollo-server-env` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023). This package's functionality is now found in the `@apollo/utils.fetcher` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details.npm WARN deprecated apollo-reporting-protobuf@3.4.0: The `apollo-reporting-protobuf` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023). This package's functionality is now found in the `@apollo/usage-reporting-protobuf` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details.npm WARN deprecated @walletconnect/client@1.4.1: WalletConnect's v1 SDKs are now deprecated. Please upgrade to a v2 SDK. For details see: https://docs.walletconnect.com/npm WARN deprecated @types/gsap@3.0.0: This is a stub types definition. gsap provides its own type definitions, so you do not need this installed.
10:30:27 AM: npm WARN deprecated @types/bech32@1.1.4: This is a stub types definition. bech32 provides its own type definitions, so you do not need this installed.
10:30:30 AM: npm WARN deprecated @ledgerhq/hw-transport-u2f@5.34.0: @ledgerhq/hw-transport-u2f is deprecated. Please use @ledgerhq/hw-transport-webusb or @ledgerhq/hw-transport-webhid. https://github.com/LedgerHQ/ledgerjs/blob/master/docs/migrate_webusb.md
10:30:32 AM: npm WARN deprecated @elrondnetwork/hw-app-elrond@0.3.0: WARNING: This project has been superseded by @multiversx/sdk-hw-provider. Use @multiversx/sdk-hw-provider instead.
10:30:32 AM: npm WARN deprecated apollo-server-core@3.12.0: The `apollo-server-core` package is part of Apollo Server v2 and v3, which are now deprecated (end-of-life October 22nd 2023). This package's functionality is now found in the `@apollo/server` package. See https://www.apollographql.com/docs/apollo-server/previous-versions/ for more details.npm WARN deprecated @floating-ui/react-dom-interactions@0.6.6: Package renamed to @floating-ui/react
10:30:32 AM: npm WARN deprecated @elrondnetwork/bls-wasm@0.3.3: WARNING: This project has been moved to @multiversx/sdk-bls-wasm. Use @multiversx/sdk-bls-wasm instead.
10:30:35 AM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
10:30:37 AM: npm WARN deprecated multibase@3.1.2: This module has been superseded by the multiformats module
10:30:39 AM: npm WARN deprecated multibase@3.1.2: This module has been superseded by the multiformats module
10:30:39 AM: npm WARN deprecated multibase@3.1.2: This module has been superseded by the multiformats module
10:30:41 AM: npm WARN deprecated multicodec@1.0.4: This module has been superseded by the multiformats module
10:30:41 AM: npm WARN deprecated multicodec@2.1.3: This module has been superseded by the multiformats module
10:30:41 AM: npm WARN deprecated multicodec@2.1.3: This module has been superseded by the multiformats module
10:30:42 AM: npm WARN deprecated uuid@2.0.1: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
10:30:42 AM: npm WARN deprecated multibase@0.7.0: This module has been superseded by the multiformats module
10:30:42 AM: npm WARN deprecated multibase@0.6.1: This module has been superseded by the multiformats module
10:30:42 AM: npm WARN deprecated multicodec@0.5.7: This module has been superseded by the multiformats module
10:30:43 AM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
10:30:43 AM: npm WARN deprecated @ledgerhq/hw-transport-u2f@5.28.0: @ledgerhq/hw-transport-u2f is deprecated. Please use @ledgerhq/hw-transport-webusb or @ledgerhq/hw-transport-webhid. https://github.com/LedgerHQ/ledgerjs/blob/master/docs/migrate_webusb.md
10:30:43 AM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
10:30:44 AM: npm WARN deprecated axios@0.19.2: Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410
10:30:46 AM: npm WARN deprecated cids@0.7.5: This module has been superseded by the multiformats module
10:30:51 AM: npm WARN deprecated @elrondnetwork/erdjs@7.0.1: WARNING: This project has been moved to @multiversx/sdk-core. Use @multiversx/sdk-core instead.
10:30:53 AM: npm WARN deprecated core-js@2.6.12: core-js@<3.23.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Some versions have web compatibility issues. Please, upgrade your dependencies to the actual version of core-js.
10:32:25 AM: added 3768 packages, and audited 3769 packages in 3m
10:32:25 AM: 523 packages are looking for funding
10:32:25 AM:   run `npm fund` for details
10:32:25 AM: 42 vulnerabilities (6 low, 22 moderate, 13 high, 1 critical)
10:32:25 AM: To address issues that do not require attention, run:
10:32:25 AM:   npm audit fix
10:32:25 AM: To address all issues possible (including breaking changes), run:
10:32:25 AM:   npm audit fix --force
10:32:25 AM: Some issues need review, and may require choosing
10:32:25 AM: a different dependency.
10:32:25 AM: Run `npm audit` for details.
10:32:25 AM: npm packages installed
10:32:26 AM: Python version set to 3.8
10:32:26 AM: Attempting Ruby version 2.7.2, read from environment
10:32:26 AM: Using Ruby version 2.7.2
10:32:27 AM: Started restoring cached go cache
10:32:27 AM: Finished restoring cached go cache
10:32:27 AM: Installing Go version 1.19.5 (requested 1.19.5)
10:32:32 AM: go version go1.19.5 linux/amd64
10:32:32 AM: Using PHP version 8.0
10:32:34 AM: Install dependencies script success
10:32:34 AM: Starting build script
10:32:34 AM: Using stage install dependencies
10:32:34 AM: Detected 1 framework(s)
10:32:34 AM: "next-nx" at version "15.9.2"
10:32:34 AM: Section completed: initializing
10:32:36 AM: ​
10:32:36 AM:   Netlify Build                                                 
10:32:36 AM: ────────────────────────────────────────────────────────────────
10:32:36 AM: ​
10:32:36 AM: ❯ Version
10:32:36 AM:   @netlify/build 29.9.0
10:32:36 AM: ​
10:32:36 AM: ❯ Flags
10:32:36 AM:   baseRelDir: true
10:32:36 AM:   buildId: 642d317850b7af73bd3937f5
10:32:36 AM:   deployId: 642d317850b7af73bd3937f7
10:32:36 AM: ​
10:32:36 AM: ❯ Current directory
10:32:36 AM:   /opt/build/repo
10:32:36 AM: ​
10:32:36 AM: ❯ Config file
10:32:36 AM:   No config file was defined: using default values.
10:32:36 AM: ​
10:32:36 AM: ❯ Context
10:32:36 AM:   production
10:32:36 AM: ​
10:32:36 AM:   1. Build command from Netlify app                             
10:32:36 AM: ────────────────────────────────────────────────────────────────
10:32:36 AM: ​
10:32:36 AM: $ nx run api:build:production
10:32:36 AM: > nx run api:build:production
10:32:40 AM: chunk (runtime: main) main.js (main) 28.3 KiB [entry] [rendered]
10:32:40 AM: webpack compiled successfully (155721fce47f77c8)
10:32:41 AM:  >  NX   Successfully ran target build for project api
10:32:41 AM:    View logs and investigate cache misses at https://cloud.nx.app/runs/OSE1A2HEDO
10:32:41 AM: ​
10:32:41 AM: (build.command completed in 4.8s)
10:32:41 AM: ​
10:32:41 AM:   2. Functions bundling                                         
10:32:41 AM: ────────────────────────────────────────────────────────────────
10:32:41 AM: ​
10:32:41 AM: Packaging Functions from dist/apps/api directory:
10:32:41 AM:  - main.js
10:32:41 AM: ​
10:33:04 AM: ​
10:33:04 AM: (Functions bundling completed in 23.4s)
10:33:04 AM: ​
10:33:04 AM:   3. Deploy site                                                
10:33:04 AM: ────────────────────────────────────────────────────────────────
10:33:04 AM: ​
10:33:04 AM: Starting to deploy site from 'apps/api/site'
10:33:05 AM: Calculating files to upload
10:33:05 AM: 0 new files to upload
10:33:05 AM: 1 new functions to upload
10:33:18 AM: The function "MAIN" is larger than the 50MB limit. Please consider reducing it.
10:33:19 AM: The function "MAIN" is larger than the 50MB limit. Please consider reducing it.
10:33:22 AM: The function "MAIN" is larger than the 50MB limit. Please consider reducing it.
10:33:24 AM: The function "MAIN" is larger than the 50MB limit. Please consider reducing it.
10:33:27 AM: The function "MAIN" is larger than the 50MB limit. Please consider reducing it.
10:33:30 AM: The function "MAIN" is larger than the 50MB limit. Please consider reducing it.
10:33:36 AM: The function "MAIN" is larger than the 50MB limit. Please consider reducing it.

Hi @nolafs, thanks for the post.

Based on the quoted build message above from the build log you posted, you’d have to work to reduce the number of pages that are part of the bundle or reduce the assets used by some Node Modules. If you’re having any other resources like images, it’s worth finding a way to reduce or strip those off too.

Also make sure you are not committing your node_modules folder.

Hope the above helps.

Thanks.