Skip to content

fix(nextjs): Correctly handle functional next config in withSentryConfig #3698

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

Merged
merged 1 commit into from
Jun 17, 2021

Conversation

lobsterkatie
Copy link
Member

To set up Sentry, we tell users to end their next.config.js files with

module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);,

where moduleExports is what was the user's module.exports before they added Sentry - in other words, all of their other config for their next app.

According to the next docs, that config can take the form either of an object or a function which returns an object. We've been correctly handling the first case, but not the second. This fixes that by checking if moduleExports is a function, and if so, running that function before merging in the user config, so that in either case we know we're merging in an object.

Fixes https://github.com/getsentry/sentry-docs/issues/3723.
Fixes ricokahler/next-plugin-preval#42.

@github-actions
Copy link
Contributor

size-limit report

Path Size
@sentry/browser - CDN Bundle (gzipped) 21.01 KB (+0.01% 🔺)
@sentry/browser - Webpack 21.89 KB (0%)
@sentry/react - Webpack 21.92 KB (0%)
@sentry/browser + @sentry/tracing - CDN Bundle (gzipped) 28.4 KB (0%)

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

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

🚀

@@ -17,6 +17,11 @@ export type NextConfigObject = {
[key: string]: unknown;
};

export type NextConfigFunction = (
phase: string,
Copy link
Member

Choose a reason for hiding this comment

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

this could be an interesting thing to experiment with in the future, like for ex. we construct different webpack configs based on dev/prod/export (if I'm understanding this correctly). https://github.com/vercel/next.js/blob/canary/packages/next/next-server/lib/constants.ts#L1-L4

Copy link
Member Author

Choose a reason for hiding this comment

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

You are. I think we might wait if/until it proves a problem, though, as I don't believe those things influence the parts of the config we muck with.

@lobsterkatie lobsterkatie merged commit d324ed1 into master Jun 17, 2021
@lobsterkatie lobsterkatie deleted the kmclb-nextjs-handle-functional-config branch June 17, 2021 18:28
lobsterkatie added a commit that referenced this pull request Jun 30, 2021
This is a bunch of prep work pulled out of an upcoming PR, which will add the option to disable the `SentryWebpackPlugin` for both server and client builds.

The changes in this PR are mostly cosmetic, with the aim of making the code more readable. The only substantive changes are:

- When modifying the webpack config options, we now clone the config object we're given.

- We now ensure that the `userNextConfig` passed to `constructWebpackConfigFunction` is an object. (We've been treating it like one, but in fact it's also possible for it to be given as a function. This is a change which should have been included in #3698.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants