fix(nextjs): Avoid importing SentryWebpackPlugin in dev mode#8543
Merged
Conversation
lopsum-me
approved these changes
Jul 15, 2023
mydea
approved these changes
Jul 17, 2023
Member
mydea
left a comment
There was a problem hiding this comment.
this is really weird and slightly concerning, but let's unblock us for now and figure out a better solution with time later!
3 tasks
723f851 to
4d12d28
Compare
Contributor
size-limit report 📦
|
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
require('@sentry/webpack-plugin')const { RawSource } = require('webpack-sources');webpack-sourcesand 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-pluginto 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 importwebpack-sources.ref #8541