Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

bundled node_modules bloat #166

Closed
khuezy opened this issue Jul 28, 2023 · 7 comments · Fixed by #167 · May be fixed by #242
Closed

bundled node_modules bloat #166

khuezy opened this issue Jul 28, 2023 · 7 comments · Fixed by #167 · May be fixed by #242

Comments

@khuezy
Copy link
Contributor

khuezy commented Jul 28, 2023

This issue is a PSA and to track future improvements to minimize lambda size.

These are dev/build deps that gets bundled, we should remove these during bundling... but for now, if you want to reduce the lambda size, manually remove them prior to deployment.

    '@esbuild',
    '@swc/core-darwin-arm64', // 33MB!
    'esbuild',
    'webpack',
    'uglify-js',
    '@webassemblyjs'

There be more, but these are the ones that take up the majority of the bloat.

NOTE: after attempting to programmatically setting this, it was too brittle to correctly handle due to the config having potential functions, which is not possible to stringify/parse the user file. And since next build runs on a child thread, we can't set the next.config at runtime.

@chorobin
Copy link

I've noticed this issue for a while. I tried to resolve it with experimental.outputFileTracingExcludes but I could never get it to work

@khuezy
Copy link
Contributor Author

khuezy commented Jul 29, 2023

I was able to get outputFileTracingExcludes to work, I'll put up a PR soon.

@chorobin
Copy link

Nice. Maybe I had something wrong with the globs

@khuezy
Copy link
Contributor Author

khuezy commented Jul 29, 2023

Trying to update the user's next.config.js file to include the outputFileTracingExcludes is not trivial, especially when they have a function in the object - it's hard to stringify and parse the function :/

We can't import the config and update the object b/c next build is executed on a different thread...

I think we'll just document the config and let users configure what they want to exclude.

@chorobin
Copy link

The extra docs would be useful for this case

@sladg
Copy link
Contributor

sladg commented Aug 5, 2023

Same as '@swc/core-darwin-arm64', // 33MB! applies to Prisma. If I specify

generator client {
    provider        = "prisma-client-js"
    binaryTargets   = ["native", "rhel-openssl-1.0.x"]
}

in schema.prisma I get both, native libquery_engine-darwin-arm64.dylib.node as well as Lambda's libquery_engine-rhel-openssl-1.0.x.so.node.

OS-specified libraries are pain and Next does not have mechanism to omit them for target infra while bundling.

@khuezy
Copy link
Contributor Author

khuezy commented Sep 12, 2023

thanks @sladg I'll put up a PR next week to remove these at build time.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
3 participants