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

fix(nextjs): Avoid importing SentryWebpackPlugin in dev mode #8543

Merged
merged 1 commit into from
Jul 17, 2023

Conversation

Lms24
Copy link
Member

@Lms24 Lms24 commented Jul 14, 2023

As reported in #8541, our NextJS SDK currently breaks dev mode for the newest NextJS 13.4.10 version

I have absolutely no idea which of the changes in 13.4.10 is causing this and the NextJS changelog doesn't help me narrow down what change might be responsible (many changes, no categories or marking of changes as relevant for build/dev, no idea where to start).

However, I traced the error back and it happens as soon as our NextJS SDK package requires @sentry/webpack-plugin:

  • @sentry/nextjs calls require('@sentry/webpack-plugin')
  • @sentry/webpack-plugin calls const { RawSource } = require('webpack-sources');
  • For whatever reason, NextJS can't require webpack-sources and throws 💥

Since we don't enable our Webpack plugin in dev mode anyway, one way to get rid of this error is to only require it if we're not in dev mode.

This hotfix therefore moves the top-level require of @sentry/webpack-plugin to a dynamic require. This isn't a great solution and honestly quite ugly but if it unblocks users for now I'd say we merge it. I think we should definitely revisit this though once we know more about why NextJS suddenly isn't able to import webpack-sources.

ref #8541

@Lms24 Lms24 requested a review from AbhiPrasad July 14, 2023 18:31
@Lms24 Lms24 marked this pull request as ready for review July 14, 2023 18:39
Copy link
Member

@mydea mydea left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really weird and slightly concerning, but let's unblock us for now and figure out a better solution with time later!

@Lms24 Lms24 force-pushed the lms/fix-nextjs-13.4.10-require-bug branch from 723f851 to 4d12d28 Compare July 17, 2023 09:08
@github-actions
Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser - ES5 CDN Bundle (gzipped + minified) 21.97 KB (+0.07% 🔺)
@sentry/browser - ES5 CDN Bundle (minified) 69.14 KB (+0.02% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped + minified) 20.3 KB (+0.07% 🔺)
@sentry/browser - ES6 CDN Bundle (minified) 60.39 KB (+0.03% 🔺)
@sentry/browser - Webpack (gzipped + minified) 21.91 KB (+0.05% 🔺)
@sentry/browser - Webpack (minified) 71.53 KB (+0.02% 🔺)
@sentry/react - Webpack (gzipped + minified) 21.93 KB (+0.03% 🔺)
@sentry/nextjs Client - Webpack (gzipped + minified) 50.58 KB (+0.01% 🔺)
@sentry/browser + @sentry/tracing - ES5 CDN Bundle (gzipped + minified) 30.12 KB (+0.05% 🔺)
@sentry/browser + @sentry/tracing - ES6 CDN Bundle (gzipped + minified) 28.17 KB (+0.05% 🔺)
@sentry/replay ES6 CDN Bundle (gzipped + minified) 49.29 KB (-0.27% 🔽)
@sentry/replay - Webpack (gzipped + minified) 42.88 KB (-0.5% 🔽)
@sentry/browser + @sentry/tracing + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 69.38 KB (-0.2% 🔽)
@sentry/browser + @sentry/replay - ES6 CDN Bundle (gzipped + minified) 61.69 KB (-0.21% 🔽)

@Lms24 Lms24 merged commit d2204eb into beta Jul 17, 2023
33 checks passed
@Lms24 Lms24 deleted the lms/fix-nextjs-13.4.10-require-bug branch July 17, 2023 09:39
Lms24 added a commit that referenced this pull request Jul 17, 2023
As reported in #8541, our NextJS SDK currently breaks dev mode for the
newest NextJS 13.4.10 version

I have absolutely no idea which of the changes in
[13.4.10](https://github.com/vercel/next.js/releases/tag/v13.4.10) is
causing this.
However, I traced the error back and it happens as soon as our NextJS
SDK package requires @sentry/webpack-plugin:

* @sentry/nextjs calls `require('@sentry/webpack-plugin')`
* @sentry/webpack-plugin calls `const { RawSource } =
require('webpack-sources');`
* For _whatever_ reason, NextJS can't require `webpack-sources` and
throws 💥

Since we don't enable our Webpack plugin [in dev
mode](https://github.com/getsentry/sentry-javascript/blob/723f851f358b75cd39da353804c51ff27ebb0c11/packages/nextjs/src/config/webpack.ts#L305)
anyway, one way to get rid of this error is to only require it if we're
_not_ in dev mode.

This hotfix therefore moves the top-level require of
`@sentry/webpack-plugin` to a dynamic require. This isn't a great
solution and honestly quite ugly but if it unblocks users for now I'd
say we merge it. I think we should definitely revisit this though once
we know more about why NextJS suddenly isn't able to import
`webpack-sources`.

ref #8541
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

Successfully merging this pull request may close these issues.

3 participants