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): Move userNextConfig.sentry to closure #5473

Merged
merged 3 commits into from Jul 27, 2022

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Jul 27, 2022

h/t to @mitchheddles for the research and initial idea - thanks!

As of vercel/next.js#38498, nextjs now warns (voluminously) if the config exported from next.config.js contains properties it doesn't recognize, including the sentry property we've been having people use to do things like disable the webpack plugin. In order to prevent these warnings, the final config returned from withSentryConfig must not have such a property, so this deletes the property from the userNextConfig object before returning it.

If we were to stop there, the warning would be gone, but so would the data userNextConfig.sentry contains. (This is true even if we run constructWebpackConfigFunction before doing the deletion, because the place we need the userNextConfig.sentry data is not in constructWebpackConfigFunction itself but in the function it returns. By the time that function is called by nextjs, the deletion will already have gone through and the data will be gone unless we keep a reference to it elsewhere.) Therefore, in order to allow the returned function to retain access the userNextConfig.sentry data, this captures it before it's deleted and passes it to constructWebpackConfigFunction, where it lives in a closure around the returned function.

fixes #5449

@Lms24 Lms24 force-pushed the kmclb-nextjs-move-sentry-config-to-closure branch from 9add59c to b41e3cd Compare July 27, 2022 09:35
@Lms24 Lms24 enabled auto-merge (squash) July 27, 2022 09:44
Lms24 added a commit that referenced this pull request Jul 27, 2022
@Lms24 Lms24 merged commit 049e6e7 into master Jul 27, 2022
@Lms24 Lms24 deleted the kmclb-nextjs-move-sentry-config-to-closure branch July 27, 2022 09:50
Lms24 added a commit that referenced this pull request Jul 27, 2022
lobsterkatie added a commit that referenced this pull request Aug 4, 2022
…5516)

In the process of working simultaneously on both #5472 (which adds the `sentry.transpileClientSDK` option to `next.config.js`) and #5473 (which moves the `sentry` options object from `next.config.js` to a new location halfway through the build process, in order to prevent nextjs from throwing warnings), I missed their overlap. As a result, the `transpileClientSDK` option is still currently being retrieved from the old, pre-move location, even though said retrieval happens in the second half of the build, after the move. (Unsurprisingly, it's therefore always undefined, rendering it useless).

This fixes that by pulling it from the new, correct location instead. It also adjusts our types so that future mistakes like this will show up as errors, by creating separate pre-move and post-move `userNextConfig` types and using them as appropriate.

Fixes #5452.
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.

Warning when using hideSourceMaps option in next.config.js
2 participants