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
@sentry/nextjs: option for hidden-source-map
instead of source-map
#3549
Comments
I temporarily solved this problem using patch-package. |
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. |
We are considering whether (and if so, when and how best) to do this. Reopening until we come to a decision. |
I tried the solution referenced above to set |
class HiddenSourceMapPlugin {
apply(compiler) {
compiler.hooks.environment.tap('HiddenSourceMapPlugin', () => {
compiler.options.devtool =
compiler.options.name === 'server' ? false : 'hidden-source-map';
});
}
} |
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 |
…ol` value (#4436) We currently force the value of the webpack option `devtool` to be `source-map`, in order to guarantee that the correct sourcemaps are generated during build. There is another `devtool` value[1], `hidden-source-map`, which produces the same maps (so just as good for our purposes), but without adding `sourceMappingURL` comments at the bottom of the resulting JS files. (Some users prefer this as a way not to have the browser complain when it tries to follow the `sourceMappingURL` link and comes up empty.) This PR adds an option that users can pass in their nextjs config, under the key `sentry.hideSourceMaps`. When this is set to true, the SDK will use `hidden-source-map` as the `devtool` value instead of `source-map`. Note that since this is a front-end-only problem, the option only applies to client-side builds. The new option is documented in getsentry/sentry-docs#4627. Fixes #3549. [1] https://webpack.js.org/configuration/devtool/
This worked for me. No need to install another plugin. All I did was paste the following code in my class HiddenSourceMapPlugin {
apply(compiler) {
compiler.hooks.environment.tap('HiddenSourceMapPlugin', () => {
compiler.options.devtool =
compiler.options.name === 'server' ? false : 'hidden-source-map';
});
}
}
const nextConfig = {
webpack(config) {
config.plugins.push(new HiddenSourceMapPlugin());
return config;
},
}; |
@disguised-uchiha You don't need to even go through all of that. Check out the change in #4436. |
Hey @lobsterkatie thanks for enabling this! QQ: why does this require the Webpack plugin to be enabled to work? We run our builds in Docker, so we can't use the Sentry Webpack plugin to upload at the same time (the asset uploading is a separate step after the build has completed). We're enabling |
It's a good question. You're right that sourcemap creation and sourcemap uploading aren't necessarily tied to one another - there's no technical reason for the requirement. The reason it exists, though, is because we don't want to be changing users' webpack configs any more than we have to. If the sentry webpack plugin is disabled, the reason for us to set the |
@lobsterkatie Fair enough, thanks for the explanation! |
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:
sentry-javascript/packages/nextjs/src/utils/config.ts
Line 151 in 60e1982
It seems the plugin only allows using
source-map
fordevtools
. Would it be possible to add an option to usehidden-source-map
instead? The current configuration leaves the reference to the source map file, causing Chrome DevTools to report a bunch ofsince I do not upload the source maps to the server. 🙁
Thanks for the consideration.
The text was updated successfully, but these errors were encountered: