Skip to content

[Bug]: Static assets being included in SSR and DSG bundles when neither is used #360

Closed
@mfanuzzi

Description

@mfanuzzi

Summary

We recently upgraded a few sites to the latest Gatsby 4.x (from 3.x) and are encountering an issue on production builds. It seems that all of the static assets for the site are included in the SSR and DSG bundles when neither is used. We do use some Gatsby /api functions so disabling these isn't really an option for us. Relevant configs:

"gatsby": "^4.12.1",
"gatsby-plugin-netlify": "4.3.0"
[[plugins]]
  package = "@netlify/plugin-gatsby"

Steps to reproduce

I can replicate this locally by running netlify build, and get the same error @overlordofmu posted in #323. I can also see when doing so that .cache/page-ssr/routes/static gets filled with every static asset on the site, which for us includes images, video files, etc. About a gig of stuff in our case.

Being we are not using SSR or DSG I have temporarily solved this by adding rm -fr ./.cache/page-ssr/routes/static/* to the build script but that is... not ideal.

Ideal solutions to me would be:

  1. Don't create SSR and DSG bundles when those features are not used
  2. Allow for exemption (or maybe opt-in) what media files get bundled

Or perhaps both?

A link to a reproduction repository

No response

Plugin version

4.0.0

More information about your build

  • I am building using the CLI
  • I am building using file-based configuration (netlify.toml)

What OS are you using?

Other (Ubuntu via WSL2)

Your netlify.toml file

`netlify.toml`
[[plugins]]
  package = "@netlify/plugin-gatsby"

[[context.production.plugins]]
  package = "netlify-plugin-image-optim"

[[context.deploy-preview.plugins]]
  package = "netlify-plugin-checklinks"
  [context.deploy-preview.plugins.inputs]
  skipPatterns = ["sw.js"]

[build]
  command = "yarn build && yarn removeSsr" # removeSsr runs `rm -fr ./.cache/page-ssr/routes/static/*`
  functions = "functions"
  publish = "public"

# redirects, etc.

Configuration

`gatsby-config.js` and options
  plugins: [
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        name: `stuff`,
        path: `${__dirname}/src/images_etc`,
      },
    },
    {
      resolve: `gatsby-plugin-netlify`,
    }
    // And others, but these stood out as relevant
 ]

Environment

Environment
  System:
    OS: Linux 4.19 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 12.47 GB / 15.64 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  npmPackages:
    @netlify/plugin-gatsby: ^3.0.0 => 3.0.0 

Gatsby info

gatsby info
 System:
    OS: Linux 4.19 Ubuntu 20.04.3 LTS (Focal Fossa)
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 16.14.2 - ~/.nvm/versions/node/v16.14.2/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 8.5.0 - ~/.nvm/versions/node/v16.14.2/bin/npm
  npmPackages:
    gatsby: ^4.12.1 => 4.12.1
    gatsby-image: ^3.9.0 => 3.11.0
    gatsby-plugin-canonical-urls: ^4.12.1 => 4.12.1
    gatsby-plugin-csp: ^1.1.3 => 1.1.3
    gatsby-plugin-emotion: ^7.12.1 => 7.12.1
    gatsby-plugin-google-fonts: ^1.0.1 => 1.0.1
    gatsby-plugin-google-tagmanager: ^4.12.1 => 4.12.1
    gatsby-plugin-json-output: ^1.2.0 => 1.2.0
    gatsby-plugin-manifest: ^4.12.1 => 4.12.1
    gatsby-plugin-mdx: ^3.12.1 => 3.12.1
    gatsby-plugin-netlify: 4.3.0 => 4.3.0
    gatsby-plugin-offline: ^5.12.1 => 5.12.1
    gatsby-plugin-react-helmet: ^5.12.1 => 5.12.1
    gatsby-plugin-root-import: ^2.0.5 => 2.0.8
    gatsby-plugin-sass: ^5.12.1 => 5.12.1
    gatsby-plugin-sharp: ^4.12.1 => 4.12.1
    gatsby-plugin-sitemap: ^5.12.1 => 5.12.1
    gatsby-remark-copy-linked-files: ^5.12.1 => 5.12.1
    gatsby-remark-images: ^6.12.1 => 6.12.1
    gatsby-source-filesystem: ^4.12.1 => 4.12.1
    gatsby-transformer-javascript-frontmatter: ^4.12.1 => 4.12.1
    gatsby-transformer-sharp: ^4.12.1 => 4.12.1

Your _redirects file

`_redirects`
# Paste content of your `_redirects` file here

Builds logs (or link to your logs)

Build logs
────────────────────────────────────────────────────────────────
  5. Functions bundling                                         
────────────────────────────────────────────────────────────────

Packaging Functions from .netlify/functions-internal directory:
 - __api/__api.js
 - __dsg/__dsg.js
 - __ssr/__ssr.js

Packaging Functions from functions directory:
 - deploy-succeeded.ts
 - submission-created.ts


(Functions bundling completed in 53.3s)

────────────────────────────────────────────────────────────────
  6. @netlify/plugin-gatsby (onPostBuild event)                 
────────────────────────────────────────────────────────────────

The function zip .netlify/functions/__dsg.zip size is 1.34 GB, which is larger than the maximum supported size of 52.4 MB.
There are a few reasons this could happen, such as accidentally bundling a large dependency or adding lots of files to "included_files".
Contains 173 files


These are the largest files in the zip:
┌─────────┬─────────────────────────────────────────────────────────────────────────────────────────────┬─────────────────┬───────────────────┐
│ (index) │                                            File                                             │ Compressed Size │ Uncompressed Size │
├─────────┼─────────────────────────────────────────────────────────────────────────────────────────────┼─────────────────┼───────────────────┤
│    1    │   '.cache/page-ssr/routes/static/video-c70b94c35291aa81ca6b78fb0ba20ade.webm'    │    '291 MB'     │     '291 MB'      │
│    2    │    '.cache/page-ssr/routes/static/video-bee9305e2e400aaa78e63e42a64c2298.mp4'    │    '252 MB'     │     '252 MB'      │
│    3    │      '.cache/page-ssr/routes/static/video-8ebf8c2bec739a7cbbfddd622fd4c679.webm'      │    '131 MB'     │     '140 MB'      │
│    4    │ '.cache/page-ssr/routes/static/anoter-video-b8066823c84855989b4caf8ac2d25922.webm' │    '119 MB'     │     '119 MB'      │
│    5    │      '.cache/page-ssr/routes/static/preparation-62b1237f6ddcd82154a847834ada0c1e.webm'      │    '98.7 MB'    │     '99.1 MB'     │
│    6    │      '.cache/page-ssr/routes/static/preparation-5b32b058b7cb19e58b9676e90d99879f.mp4'       │    '89.6 MB'    │     '90.8 MB'     │
│    7    │      '.cache/page-ssr/routes/static/video-82bd05daffa5bcbc50795019b2d3a8da.mp4'       │    '89.6 MB'    │     '90.8 MB'     │
│    8    │ '.cache/page-ssr/routes/static/anoter-video-043d78ba5bc9710c3c9429ca4d549e19.mp4'  │    '87.1 MB'    │     '87.4 MB'     │
│    9    │         '.cache/page-ssr/routes/static/admin-5a8191bbb8ff68a699e4d43eb2873e81.webm'         │    '82.9 MB'    │     '83.3 MB'     │
│   10    │         '.cache/page-ssr/routes/static/admin-ed22d6edfc4f1394034bb525ddff783a.mp4'          │    '72.3 MB'    │     '73.6 MB'     │
└─────────┴─────────────────────────────────────────────────────────────────────────────────────────────┴─────────────────┴───────────────────┘
The function zip .netlify/functions/__ssr.zip size is 1.34 GB, which is larger than the maximum supported size of 52.4 MB.
There are a few reasons this could happen, such as accidentally bundling a large dependency or adding lots of files to "included_files".
Contains 173 files


These are the largest files in the zip:
┌─────────┬─────────────────────────────────────────────────────────────────────────────────────────────┬─────────────────┬───────────────────┐
│ (index) │                                            File                                             │ Compressed Size │ Uncompressed Size │
├─────────┼─────────────────────────────────────────────────────────────────────────────────────────────┼─────────────────┼───────────────────┤
│    1    │   '.cache/page-ssr/routes/static/video-c70b94c35291aa81ca6b78fb0ba20ade.webm'    │    '291 MB'     │     '291 MB'      │
│    2    │    '.cache/page-ssr/routes/static/video-bee9305e2e400aaa78e63e42a64c2298.mp4'    │    '252 MB'     │     '252 MB'      │
│    3    │      '.cache/page-ssr/routes/static/video-8ebf8c2bec739a7cbbfddd622fd4c679.webm'      │    '131 MB'     │     '140 MB'      │
│    4    │ '.cache/page-ssr/routes/static/anoter-video-b8066823c84855989b4caf8ac2d25922.webm' │    '119 MB'     │     '119 MB'      │
│    5    │      '.cache/page-ssr/routes/static/preparation-62b1237f6ddcd82154a847834ada0c1e.webm'      │    '98.7 MB'    │     '99.1 MB'     │
│    6    │      '.cache/page-ssr/routes/static/preparation-5b32b058b7cb19e58b9676e90d99879f.mp4'       │    '89.6 MB'    │     '90.8 MB'     │
│    7    │      '.cache/page-ssr/routes/static/video-82bd05daffa5bcbc50795019b2d3a8da.mp4'       │    '89.6 MB'    │     '90.8 MB'     │
│    8    │ '.cache/page-ssr/routes/static/anoter-video-043d78ba5bc9710c3c9429ca4d549e19.mp4'  │    '87.1 MB'    │     '87.4 MB'     │
│    9    │         '.cache/page-ssr/routes/static/admin-5a8191bbb8ff68a699e4d43eb2873e81.webm'         │    '82.9 MB'    │     '83.3 MB'     │
│   10    │         '.cache/page-ssr/routes/static/admin-ed22d6edfc4f1394034bb525ddff783a.mp4'          │    '72.3 MB'    │     '73.6 MB'     │
└─────────┴─────────────────────────────────────────────────────────────────────────────────────────────┴─────────────────┴───────────────────┘```

</details>


### Function logs

<details>
  <summary>Function logs</summary>
  

Paste logs here


</details>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions