[nextjs] Fix build errors when app uses personalize initializer, add utils, site submodule exports #1430
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.
Description / Motivation
NextJS version 13.3 has fixed some issues related to server imports in client context. This has caused some errors to occur when an import in a client component would also cause nextjs/server to be imported, like this one: vercel/next.js#48251
This PR moves SiteInfo, SiteResolver and tryParseEnvValue exports from '@sitecore-jss/sitecore-jss-nextjs/middleware' to separate submodules, in order to avoid these imports dragging server logic into a client bundle during build.
It's also possible to fix this issue by adding a next-config plugin to patch webpack configuration in a sample app. The patch would prevent loading 'fs' in client context (this would be a non-breaking approach), but that would be more of a workaround than a future-proof fix.
Testing Details
Types of changes