question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@next/swc is not a development dependency (blowing Heroku slug size)

See original GitHub issue

What version of Next.js are you using?

12.0.7

What version of Node.js are you using?

14.15.4

What browser are you using?

Chrome

What operating system are you using?

Linux

How are you deploying your application?

Heroku

Describe the Bug

Heroku limits the compressed size of the app folder to 500 MB. Somehow, the total compressed size of the app went from 200 to 600, after upgrading from Next 11 to 12.

After investigating the problem, the issue is that somehow, all the binaries for SWC are included in the build and not removed when running npm prune.

$ du -ha --max-depth 3 /app | sort -hr | grep @next
481M	/app/node_modules/@next
48M	/app/node_modules/@next/swc-linux-x64-gnu
48M	/app/node_modules/@next/swc-android-arm64
47M	/app/node_modules/@next/swc-linux-x64-musl
47M	/app/node_modules/@next/swc-linux-arm64-musl
47M	/app/node_modules/@next/swc-linux-arm64-gnu
47M	/app/node_modules/@next/swc-linux-arm-gnueabihf
44M	/app/node_modules/@next/swc-win32-x64-msvc
40M	/app/node_modules/@next/swc-win32-arm64-msvc
40M	/app/node_modules/@next/swc-darwin-x64
38M	/app/node_modules/@next/swc-win32-ia32-msvc
38M	/app/node_modules/@next/swc-darwin-arm64
1.8M	/app/node_modules/@next/react-dev-overlay
68K	/app/node_modules/@next/react-refresh-utils
32K	/app/node_modules/@next/env
28K	/app/node_modules/@next/polyfill-module
....

The actual problem is that because those are binaries, they barely compress, so they really break the slug size limit of heroku.

Expected Behavior

Given that the build was already completed, I imagine it is unnecessary to have this packages in production. We should allow these packages to be removed by npm prune.

To Reproduce

Deploy any Next 12 app to Heroku.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
carlosbarazacommented, Dec 8, 2021

For Heroku and NextJS 12.0.7, I had to add the following custom Heroku build steps to package.json:

Disable SWC compiler because of #31855

"heroku-postbuild": "echo '{\"presets\": [\"next/babel\"]}' > .babelrc && npm run build",

Remove SWC and .next/cache to reduce the slug size:

"heroku-cleanup": "rm -rf .next/cache && find node_modules/@next -depth -maxdepth 1 -type d -name 'swc*' -exec rm -rf {} \\; -prune #Remove cache and SWC binaries to reduce heroku slug size",

Hope this workaround helps someone.

0reactions
github-actions[bot]commented, Oct 1, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Reduce heroku slug size while whitelisting 'serve' and its ...
How to reduce heroku slug size while whitelisting 'serve' and its dependencies ? For now, I'm excluding some big independent packages (e.g. @mui ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found