After upgrading to to 9.5.2, client bundle includes unnecessary browser-node-polyfills
See original GitHub issueBug report
Describe the bug
After upgrading to next@9.5.2, client bundle includes browser polyfils for Node.js
, probably related to #16022.
As far as I can tell, no code relies on these modules, because doing
delete config.resolve.alias.crypto;
delete config.resolve.alias.stream;
delete config.resolve.alias.path;
delete config.resolve.alias.buffer;
delete config.resolve.alias.vm;
in next.config.js
removes the modules from the bundle, but the code still works.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
- Upgrade to next 9.5.2
- Bundle your code
- Inspect the output
I realise that this will not be easy to debug, since it probably is related to our setup, which is closed source (sorry).
Expected behavior
Unnecessary browser node polyfills should not be in the bundle
Screenshots
System information
- OS:macOS
- Version of Next.js: 9.5.2
- Version of Node.js: 12.18.3
Additional context
My best guess is that some code only running on the server causes this to be bundled, even though it is not used on the client.
Any help with further debugging would be awesome, just knowing why these are ending up being a part of the bundle. What dependency triggers these to be bundled.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9 (7 by maintainers)
Top GitHub Comments
I can confirm this. Our numbers under “First Load JS” grew from around 100KB to more than 300KB per page! Our application uses
sockjs-client
. If I disable this import, the sizes go back back to normal.I was able to track this down to
9.5.2-canary.10
(with9.5.2-canary.9
, everything was still OK), so I guess @tbergq is right that it must have something to do with #16022Adding the
delete
lines tonext.config.js
as @tbergq suggested actually resolves the problem. Thanks for the workaround!Our application is open-source. It can be found here: https://github.com/steep-wms/steep/tree/master/ui
Let me know if I should try to create a minimal example.
I managed to find out the reason that we got these node-polyfills bundled.
We have a dependency that depends on
seedrandom
.That package also sets
browser: {crypto: false}
in package jsonIf I set this dependency as external, node-polyfills are no longer bundled.
So the issue is the same as @michel-kraemer is describing.