Skip to content

Enable Production Source Maps for Improved Frontend Error Traceability #1567

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

rishyym0927
Copy link
Contributor

This PR enables production source maps in the Next.js frontend configuration by setting productionBrowserSourceMaps: true. This change allows error reporting tools like Sentry to display readable, unminified stack traces referencing the original source files, making frontend error reports much easier to debug.

Fixes #1561

Copy link
Contributor

coderabbitai bot commented Jun 8, 2025

Summary by CodeRabbit

  • Chores
    • Enabled generation of source maps for production builds to improve debugging and error tracking.
      """

Summary by CodeRabbit

  • Chores
    • Enabled generation of source maps for production builds to improve debugging and error tracing.

Walkthrough

The Next.js configuration was updated to enable production browser source maps by setting productionBrowserSourceMaps to true in next.config.ts. This change allows source maps to be generated during production builds, facilitating improved debugging and error tracing in production environments.

Changes

File(s) Change Summary
frontend/next.config.ts Enabled production browser source maps in Next.js config.

Assessment against linked issues

Objective Addressed Explanation
Enable source maps for better stack trace readability (#1561)

Assessment against linked issues: Out-of-scope changes

No out-of-scope changes found.

Suggested reviewers

  • arkid15r
    """

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ceb01c5 and e14cda3.

📒 Files selected for processing (1)
  • frontend/next.config.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/next.config.ts
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
frontend/next.config.ts (1)

7-7: Improve source map security and formatting.

  • Adjust indentation to align with the existing 2-space style.
  • Prevent serving .map files to end users while still uploading them to Sentry by using the Sentry Webpack Plugin option stripSourceMappingUrl.
--- a/frontend/next.config.ts
@@ const nextConfig: NextConfig = {
-   productionBrowserSourceMaps: true, // Enable source maps for production
+  productionBrowserSourceMaps: true,  // Enable source maps for production
--- a/frontend/next.config.ts
@@ export default withSentryConfig(nextConfig, {
-  disableLogger: false,
+  disableLogger: false,
+  stripSourceMappingUrl: true  // removes sourceMappingURL comments from shipped files
})
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6b0757a and ceb01c5.

📒 Files selected for processing (1)
  • frontend/next.config.ts (1 hunks)

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

@rishyym0927 are you sure this is enough to enable Sentry source map uploads?

@rishyym0927
Copy link
Contributor Author

@rishyym0927 are you sure this is enough to enable Sentry source map uploads?

According to the documentation and the research I have done, it should work. But since I cant build and deploy this project to real world, I cant be very sure of it! And thats the only way to verify

@arkid15r
Copy link
Collaborator

arkid15r commented Jun 9, 2025

@rishyym0927 are you sure this is enough to enable Sentry source map uploads?

According to the documentation and the research I have done, it should work. But since I cant build and deploy this project to real world, I cant be very sure of it! And thats the only way to verify

Any references please?

@rishyym0927
Copy link
Contributor Author

This is the official response I got through AI from Sentry Official Website @arkid15r ->

The productionBrowserSourceMaps option is a Next.js configuration setting that controls whether source maps are generated for browser (client-side) code during production builds. When set to true, Next.js will generate source maps for your client-side bundles, which can then be uploaded to Sentry to enable readable stack traces for errors in production.

Key points from the knowledge sources:

  • Setting productionBrowserSourceMaps: true in your next.config.js enables the generation of browser source maps during production builds. This is necessary if you want Sentry to provide unminified stack traces for client-side errors in production environments NextJS Partial Absolute Path Match for Sourcemap.
  • If you disable this option (productionBrowserSourceMaps: false), source maps will not be generated for the browser, which means Sentry will not be able to unminify stack traces for client-side errors. This can make debugging production issues more difficult productionBrowserSourceMaps: false is not working - a way to disable the sourcemaps.
  • The Sentry Next.js SDK may override or interact with this setting, especially if you use the withSentryConfig wrapper. There have been issues and fixes related to how this setting is respected in different SDK versions Client-side sourceMappingURL is being erased despite of settings.
  • Disabling source maps can help with build performance and memory usage, but the trade-off is losing readable stack traces in Sentry. This is a common workaround for "out of memory" errors during builds, but it comes with the downside of less useful error reports "Out of Memory" ("OOM") event during next build (Vercel).

Example usage in next.config.js:

const nextConfig = {
  productionBrowserSourceMaps: true,
  // ...other config
};

module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions);

Summary:
Set productionBrowserSourceMaps: true to generate client-side source maps in production, which are necessary for Sentry to provide readable stack traces. Disabling it improves build performance but reduces error traceability in Sentry. If you need to hide source maps from the public, consider using the hideSourceMaps option or deleting them after upload, but keep in mind the implications for debugging productionBrowserSourceMaps: false is not working - a way to disable the sourcemaps.

@rishyym0927 rishyym0927 requested a review from arkid15r June 10, 2025 07:11
@arkid15r
Copy link
Collaborator

withSentryConfig

It looks like the main part (withSentryConfig) is not covered in the PR.

@rishyym0927
Copy link
Contributor Author

withSentryConfig

It looks like the main part (withSentryConfig) is not covered in the PR.

should I work on this and update you on the progress?

Copy link

@arkid15r
Copy link
Collaborator

withSentryConfig

It looks like the main part (withSentryConfig) is not covered in the PR.

should I work on this and update you on the progress?

The issue is Implement Sentry source maps support so yes -- I expect it to be addressed. The source maps generation itself is not that helpful for bug troubleshooting in Sentry.

@arkid15r
Copy link
Collaborator

#19 50.42 [@sentry/nextjs - Client] Warning: No auth token provided. Will not upload source maps. Please set the authToken option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/

https://github.com/OWASP/Nest/actions/runs/15719115963/job/44296500205#step:8:430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Sentry source maps support
2 participants