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.

After upgrading to to 9.5.2, client bundle includes unnecessary browser-node-polyfills

See original GitHub issue

Bug 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:

  1. Upgrade to next 9.5.2
  2. Bundle your code
  3. 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

Screenshot 2020-08-17 at 14 59 16

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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
michel-kraemercommented, Aug 17, 2020

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 (with 9.5.2-canary.9, everything was still OK), so I guess @tbergq is right that it must have something to do with #16022

Adding the delete lines to next.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.

1reaction
tbergquist-godaddycommented, Aug 19, 2020

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 json

If I set this dependency as external, node-polyfills are no longer bundled.

So the issue is the same as @michel-kraemer is describing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

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