While applying the sourcemaps to stack traces may be useful in development, when you're trying to debug stack traces in production and re-applying the sourcemaps it does not work as they've been rewritten.
We track exceptions with Sentry and upload our application sourcemaps via their release management tool (mainly for server side sourcemaps). However, all the errors that reach the _error page have been rewritten, so we don't get the correct mappings. See below:
Without automatic sourcemaps / Original error (Expected 馃憤)
Stack traces point to our original bundle file line numbers and columns, sourcemap is then applied and source is shown correctly:

With automatic sourcemaps (Actual 馃憥)
Stack traces point to files that don't exist. Even though the line numbers map correctly to the original source, we don't have it anymore to find the problem.

Could we disable this automatically in production builds (both client and server) or at least have an option to disable it? Or alternatively, apply the sourcemaps just before rendering in the ErrorDebug page, while sending the real error to Error.getInitialProps so we can capture it correctly. Also, when it bubbles to the window, having the real url would point to the file in the dev console source, instead of non-existent/malformed file path that 404s at the moment.
I've seen that the @canary version has rewritten all of this. Are sourcemaps still gonna be applied in the next major version?
Capturing the exception ourselves to get the original stack trace (e.g. wrapping hoisted getInitialProps in _app), but this does not capture all the possible exceptions and is not centralized.
Is there any alternative right now to get the original error?
We no longer rewrite stacktraces on latest canary, we only render rewritten stacktraces in dev with react-error-overlay.
@joaovieira How do you upload application sourcemaps to Sentry so that Sentry will recognize .ts files?
same question with u @Utwo
@Utwo @pmjhonwang I simply use the Sentry CLI (https://docs.sentry.io/clients/javascript/sourcemaps/#upload-sourcemaps-with-cli), though there are other ways. Just make sure you're generating sourcemaps on your build (e.g. with withSourcemaps) and you may need to play with the CLI a bit to get the --url-prefix right.
Thanks, I've solved it like this:
sentry-cli releases files ${TAG} upload-sourcemaps --url-prefix=~/_next/static ./.next/static
sentry-cli releases files ${TAG} upload-sourcemaps \
--url-prefix=~/_next/\"$(cat ./.next/BUILD_ID)\"/page \
./.next/server/bundles/pages"
Ah, now I understand where the problem was. Yeah, I next export everything into a folder (which I deploy to a CDN) and upload everything from there. This also runs from a docker container after deploy, so there's only one version of the app in there. No need to find BUILD_ID, etc.