Skip to content
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

Error checking package import bundle size for node packages with size-limit-preset-node-lib #306

Open
slavik-chapelskyi opened this issue Dec 13, 2022 · 6 comments

Comments

@slavik-chapelskyi
Copy link
Contributor

I have tried to implement this tool in our monorepo containing only node specific packages or both browser/node compatible.

I'm facing issues using @size-limit/preset-small-lib preset of a node library, which is using node-fetch package. After running check the bundle was surprisingly small. After investigation I have figured out that whole node-fetch package was replace with some small esbuild global.fetch polyfill. That probably because it was build for web, not node platform.
So I have switched preset to https://github.com/un-ts/size-limit/tree/main/packages/preset-node-lib and try to run bundle check with it. But it refuses to working with import option. I have also tried to change the CLI --save-bundler option to check the output without import option, but it had the same error, so its impossible to properly check the bundle size for node packages.

CleanShot 2022-12-13 at 18 16 01@2x

CleanShot 2022-12-13 at 18 16 59@2x

@ai
Copy link
Owner

ai commented Dec 13, 2022

After investigation I have figured out that whole node-fetch package was replace with some small esbuild global.fetch polyfill

It is expected behavior. Why it doesn’t work for you?

@slavik-chapelskyi
Copy link
Contributor Author

After investigation I have figured out that whole node-fetch package was replace with some small esbuild global.fetch polyfill

It is expected behavior. Why it doesn’t work for you?

Because the package I'm checking bundle size is developed to be used in node projects only, and I'm interested in what the actual bundle size for node project not supporting fetch

@ai
Copy link
Owner

ai commented Dec 13, 2022

In my world, there is no such thing as bundle size for Node.js project since you do not need bundlers for Node.js.

What do you mean for “bundle” in Node.js and why do you care about it’s size?

@slavik-chapelskyi
Copy link
Contributor Author

Our backend is build on top of AWS lambda, which have size limit of 50mb.
So there is cold start problem when it comes to lamdas https://khalilstemmler.com/blogs/serverless/5-ways-to-manage-lambda-cold-starts/#Understanding-the-Cold-Start-Problem
While bundle size is not primary first problem with cold starts, we are still care about reusable packages bundle size to make it each lambda as small as possible, to ensure smaller cold starts

@slavik-chapelskyi
Copy link
Contributor Author

I was able to fix this by replacing size-limit-preset-node-lib with undocumented modifyEsbuildConfig option and setting esbuild platform to node.

CleanShot 2022-12-13 at 18 54 26@2x

@ai
Copy link
Owner

ai commented Dec 13, 2022

Interesting problem :-/

Seems like you need to set custom esbuild config with a target to Node.js https://esbuild.github.io/api/#target

It will disable auto-polyfills.

Try to use config option in Size Limi config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants