New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@next/swc is not a development dependency (blowing Heroku slug size) #32183
Comments
For Heroku and NextJS 12.0.7, I had to add the following custom Heroku build steps to 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. |
@balazsorban44 I guess the |
@carlosbaraza your solution looks really awesome, I'll try it later today. But still I think it's a bad idea from NextJS devs to auto include all the binaries in the bundle. For example, Prisma only includes the engine binary you need. |
For anyone else - this is what got us below the heroku slug size limit: rm -rf .next/cache;
# Remove these from node_modules because very large
find node_modules/@next -depth -maxdepth 1 -type d -name 'swc*' -exec rm -rf {} \\; -prune;
find node_modules/@swc -depth -maxdepth 1 -type d -name 'core-win*' -exec rm -rf {} \\; -prune;
find node_modules/@swc -depth -maxdepth 1 -type d -name 'core-android*' -exec rm -rf {} \\; -prune; |
Hi, this should not be the case unless you are force installing all optional dependencies. Further you can optimize deployment size by leveraging the I'm gonna close this as this shouldn't be an issue in the latest version with up to date versions of your package manager. |
@ijjk - Thank you for those pointers, seriously. For those tripping over this issue in the future: https://stackoverflow.com/questions/69159313/prevent-optional-dependencies-to-be-installed-on-heroku To set 'optional dependencies' on heroku: $ heroku config:set --app $APP_NAME NPM_CONFIG_OMIT=optional @ijjk Do you have any insight into how you use the For example: // This handler in my custom server
const nextJsHandler = app.getRequestHandler(); // Does the presence of the `.next/standalone` make this behave differently? It doesnt seem using next@12.2.5 |
@ijjk - Rounding back on this, it does not appear that Also - forgot to remove find node_modules/@next -depth -maxdepth 1 -type d -name 'swc*' -exec rm -rf {} \; -prune;
find node_modules/@swc -depth -maxdepth 1 -type d -name 'core-win*' -exec rm -rf {} \; -prune;
find node_modules/@swc -depth -maxdepth 1 -type d -name 'core-android*' -exec rm -rf {} \; -prune;
find node_modules/@swc -depth -maxdepth 1 -type d -name 'core-darwin*' -exec rm -rf {} \; -prune; |
@wi-ski how are you installing your dependencies only the relevant version should be installed for your platform
|
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. |
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
.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.
The text was updated successfully, but these errors were encountered: