sveltejs / kit

web development, streamlined
https://kit.svelte.dev
MIT License
18.56k stars 1.91k forks source link

Vercel complains about severless function exceeding 50MB size, because of an unused import, when I thought unused imports were removed on build #10430

Closed jhubbardsf closed 1 year ago

jhubbardsf commented 1 year ago

Describe the bug

I was helping a friend debug their app and Vercel started complaining that the build was exceeding the 50MB Serverless Function limitation it has. The error ended up being that an intern had accidentally imported import { request } from '@playwright/test'; into a +server.ts API route which bloated the function beyond the 50MB limit because of how large that package is. But here's my confusion:

The intern had accidentally imported it and then not even used it. It was my understanding that an unused import like that would be stripped from the build (and a local pnpm build, and looking at the file sizes, seems to back that up). So is this a misunderstanding of what SvelteKit does on my part, a problem with the Vercel-Adapter, or something else possibly going on?

Reproduction

Sadly can't fork and show the repo since it's proprietary work but if my explanation isn't enough I can try to recreate it in a new repo.

Logs

No response

System Info

System:
    OS: macOS 14.0
    CPU: (12) arm64 Apple M2 Max
    Memory: 627.84 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.16.1 - ~/.nvm/versions/node/v18.16.1/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 9.5.1 - ~/.nvm/versions/node/v18.16.1/bin/npm
    pnpm: 8.6.3 - ~/Library/pnpm/pnpm
  Browsers:
    Brave Browser: 115.1.56.11
    Chrome: 115.0.5790.102
    Safari: 17.0
  npmPackages:
    @sveltejs/adapter-vercel: 2.4.3 => 2.4.3
    @sveltejs/kit: ^1.20.0 => 1.20.0
    svelte: ^3.58.0 => 3.58.0
    vite: ^4.3.3 => 4.3.3

Severity

serious, but I can work around it

Additional Information

No response

elliott-with-the-longest-name-on-github commented 1 year ago

It wouldn't shock me if this is because @playwright/test doesn't have sideEffects: false in its package.json. Rollup doesn't know it's side-effect free, so it doesn't strip it. You could test this by adding that key to its package.json in node_modules and then building.

benmccann commented 1 year ago

I believe this is working as intended and you can modify the behavior with: https://rollupjs.org/configuration-options/#treeshake-modulesideeffects