fix(nextjs): Fix typing issue with withSentryConfig
and NextConfig
#5967
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.
Closes #4560
This was super nasty to fix!
I managed to fix the reported
null
issue and a couple of other minor differences too, I finally get stuck on this horror:The issue is that
NextJsWebpackConfig
has the propertyconfig: NextConfigComplete
andNextConfigComplete
isRequired<NextConfig>
. I could go through and add the 33 missing properties to the vendoredNextConfigObject
but it will get broken as soon as new properties get added.I spent an age trying to work out how to fix this and it basically comes down to the fact that
Required
is evil and makes creating vendored types close to impossible, especially when you rely on the detail of those vendored types in your own code.I resigned myself to making the smallest change somewhere to
any
and found that I could do that with theconfig
inBuildContext
. So we don't lose type safety in the Sentry code, I had to addconfig as NextConfigObject
where appropriate.This PR also adds a
test:types
script which runs after the integration tests and ensures that this doesn't get broken in the future. It has apackage.json
that means that we can test against the next v12 types. I did try updating@sentry/nextjs
to devDepend on v12 but it threw up a few errors and I wasn't convinced this was a good idea.