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.

@sentry/nextjs Webpack 5 code duplication bug

See original GitHub issue

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other: @sentry/nextjs

Version:

6.4.1

Description

During the process of upgrading one of our next.js applications from webpack 4 to webpack 5 I stumbled upon a bug where using withSentryConfig causes webpack 5 to duplicate dependencies in the final output. Using the webpack bundle analyzer I can see that packages normally bundled in _app also get their own shared bundle

Without withSentryConfig:

Screen Shot 2021-05-24 at 3 31 44 PM

Using withSentryConfig: (Notice that @apollo/client is now included in both _app and the 675- bundle)

Screen Shot 2021-05-24 at 3 32 29 PM

I’ve created a simple app using the with-apollo template that reproduces the issue: https://github.com/pgrippi/sentry-nextjs-code-duplication-bug.

You can modify next.config.js, swapping the module.exports statements and running yarn build to see the bundle output difference

To clarify the issue not limited to @apollo/client, it looks like most modules imported from npm that appear in both _app and other pages get duplicated, the apollo client is just very noticeable given its large footprint

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
lobsterkatiecommented, Jun 4, 2021

What @tm1000 said. 🙂

Also, @steida, you’re not wrong - it is a comparatively big library, and one of our goals for v7 is to reduce the bundle size. The way it’s currently written makes it not very tree-shakable (we use classes a lot, for instance), and we aim to fix that, among other things.

Glad the update fixed things! Nothing like investigating a bug and discovering you’ve unknowingly fixed it after unknowingly introducing it in the first place…

2reactions
lobsterkatiecommented, Jun 4, 2021

@pgrippi @travisbloom @adrienrn @steida Can you all please try upgrading to @sentry/nextjs 6.5.0 or greater? I believe I understand the cause of this bug, and if I do, then it’s fixed in that version.

More specifically, https://github.com/getsentry/sentry-javascript/pull/3625 (which is included in https://github.com/getsentry/sentry-javascript/pull/3580) fixed a bug where the webpack entry property was incorrectly converted to a promise, rather than a function which returns a promise. As a result, this code was broken - originalEntry wasn’t a function, so it wasn’t awaited, and therefore never turned into a real value; the promise that it remained didn’t have the keys necessary for the final for-loop; and therefore none of the dependsOn code (which would have factored the duplication out) could run.

Can y’all please let me know if upgrading works for you?

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Sentry/Next.js] Not working with Webpack 5 on Next.js 11 #3688
When trying to start my app with next 11, where webpack 5 is enabled by default I get the following error: [Sentry] Could...
Read more >
@sentry/nextjs Webpack 5 code duplication bug - - Bountysource
Coming soon: A brand new website interface for an even better experience!
Read more >
Manual Setup for Next.js - Sentry Documentation
Use withSentryConfig to extend the default Next.js usage of Webpack. This will do two things: Automatically call the code in sentry.server.config.js and sentry ......
Read more >
Preventing Duplication by "Splitting" Shared Code ... - Symfony
To solve this, you can ask webpack to analyze your files and split them into additional files, which will contain "shared" code. To...
Read more >
@sentry/utils | Yarn - Package Manager
This option makes WebPack transpile the SDK code to the same transpilation level as the user code. By specifying this option, the Next.JS...
Read more >

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