@sentry/nextjs: option for `hidden-source-map` instead of `source-map`

See original GitHub issue

Firstly, thanks for all your hard work, Sentry is one of the best development tools out there, hands down. 👍

I have a small request for the new @sentry/nextjs plugin. Based on this line here: https://github.com/getsentry/sentry-javascript/blob/60e1982f71b2c7fb664a5adb38d0d730810101ec/packages/nextjs/src/utils/config.ts#L151

It seems the plugin only allows using source-map for devtools. Would it be possible to add an option to use hidden-source-map instead? The current configuration leaves the reference to the source map file, causing Chrome DevTools to report a bunch of

DevTools failed to load SourceMap: Could not load content for https://...: HTTP error: status code 404, net::ERR_HTTP_RESPONSE_CODE_FAILURE

since I do not upload the source maps to the server. 🙁

Thanks for the consideration.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

6reactions
AlexBeauchemincommented, Nov 16, 2021

I created a webpack plugin which remove all sourcemaps after sentry’s upload and implement @hellojser solution to remove the sourcemap references to avoid 404 errors by browser calling the unexisting map files

https://github.com/AlexBeauchemin/webpack-delete-sourcemaps-plugin

6reactions
kamilogorekcommented, May 17, 2021

withSentryConfig which is used to generate the config is nothing else than a function that processes input config, and outputs updated one. There’s nothing that’d stop you from changing any of the values once it’s processed.

Based on this docs: https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/#extend-default-webpack-usage-for-source-maps

Given this config (shortened for readabilty):

const { withSentryConfig } = require("@sentry/nextjs");
// ...
module.exports = withSentryConfig(moduleExports, SentryWebpackPluginOptions);

You can write:

const { withSentryConfig } = require("@sentry/nextjs");
// ...
const sentryConfig = withSentryConfig(moduleExports, SentryWebpackPluginOptions);
const stashedWebpackConfig = sentryConfig.webpack;
sentryConfig.webpack = (config, options) => {
  const updatedConfig = stashedWebpackConfig(config, options);
  // see: https://github.com/vercel/next.js/blob/master/errors/improper-devtool.md
  if (!options.dev) {
    updatedConfig.devtool = 'hidden-source-map';
  }
  return updatedConfig;
}
module.exports = sentryConfig;

While definitely not perfect, it should let you get unblocked.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting Source Maps for Next.js
If you find that Sentry is not mapping filename, line, or column mappings correctly, you should verify that your source maps are functioning...
Read more >
Advanced Features: Source Maps | Next.js
Enables browser source map generation during the production build.
Read more >
[nextjs] Original source code visible in browser dev tools #4489
For nextjs config using withSentryConfig, we can't set the devtool value to hidden-source-map as it's overriden by the sentry config wrapper.
Read more >
Next.js source maps with typescript on Sentry - Stack Overflow
Is there anyway to get the source maps to work with sentry (without the Enable JavaScript source fetching and without leaving the source...
Read more >
Source Maps for JavaScript - Sentry Documentation
Sentry supports un-minifying JavaScript via source maps, which lets you view source code context obtained from stack traces in their original untransformed ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found