Skip to content
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

Client-side sourceMappingURL is being erased despite of settings #12219

Closed
3 tasks done
aacheblukov opened this issue May 24, 2024 · 4 comments · Fixed by #12278
Closed
3 tasks done

Client-side sourceMappingURL is being erased despite of settings #12219

aacheblukov opened this issue May 24, 2024 · 4 comments · Fixed by #12278
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug

Comments

@aacheblukov
Copy link

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/nextjs

SDK Version

8.4.0

Framework Version

Next 14.1.1

Link to Sentry event

https://sentry.testgrigorev-aks.arkadiumhosted.com/organizations/arkadium-test-sentry/issues/302/?query=is%3Aunresolved&referrer=issue-stream&stream_index=0

SDK Setup

sentry.client.config.ts

import * as Sentry from '@sentry/nextjs';

const isProd = process.env.BUILD_ENV === 'production';
Sentry.init({
    dsn: process.env.SENTRY_DSN,
    environment: process.env.BUILD_ENV,
    tracesSampleRate: isProd ? 0.1 : 1,
    debug: false,
    replaysOnErrorSampleRate: isProd ? 0.1 : 1.0,
    replaysSessionSampleRate: isProd ? 0.1 : 1.0,

    integrations: [
        Sentry.replayIntegration({
            maskAllText: false,
            blockAllMedia: false,
        }),
        Sentry.browserTracingIntegration(),
        
    ],
});

instrumentation.ts

import * as Sentry from '@sentry/nextjs';
export async function register() {
    const isProd = process.env.BUILD_ENV === 'production';
    Sentry.init({
        dsn: process.env.SENTRY_DSN,
        environment: process.env.BUILD_ENV,
        release: process.env.SENTRY_RELEASE,
        tracesSampleRate: isProd ? 0.1 : 1,
        debug: false,
    });
}

nextjs.config.js

const { withSentryConfig } = require('@sentry/nextjs');

/** @type {import('next').NextConfig} */
const nextConfig = {
    env: {
        SENTRY_AUTH_TOKEN: process.env.SENTRY_AUTH_TOKEN,
        SENTRY_RELEASE: process.env.SENTRY_RELEASE,
        SENTRY_DSN: process.env.SENTRY_DSN,
        BUILD_ENV: process.env.BUILD_ENV,
    },
    output: 'standalone',
    reactStrictMode: false,
    productionBrowserSourceMaps: true,
    experimental: {
        instrumentationHook: true,
    },
    images: {
        remotePatterns: [
            {
                protocol: 'https',
                hostname: 'cdn.com',
                port: '',
                pathname: '/**',
            },
        ],
    },
    async rewrites() {
        return [
            {
                source: '/',
                destination: '/home',
            },
        ];
    },
};
const sentryWebpackPluginOptions = {
    // Additional config options for the Sentry webpack plugin. Keep in mind that
    // the following options are set automatically, and overriding them is not
    // recommended:
    //   release, url, configFile, stripPrefix, urlPrefix, include, ignore
    release: process.env.SENTRY_RELEASE,
    environment: process.env.BUILD_ENV,
    org: process.env.SENTRY_ORG,
    project: process.env.SENTRY_PROJECT,
    url: process.env.SENTRY_URL,
    authToken: process.env.SENTRY_AUTH_TOKEN,

    widenClientFileUpload: true,

    transpileClientSDK: true,
    tunnelRoute: '/monitoring',
    disableLogger: true,
    debug: true,
    telemetry: false,


    automaticVercelMonitors: true,

};

// Make sure adding Sentry options is the last code to run before exporting
module.exports = withSentryConfig(nextConfig, sentryWebpackPluginOptions);

Steps to Reproduce

  1. yarn build
  2. check /.next/server/app/[...slug]/page.js
  3. There is //# sourceMappingURL=page.js.map string
  4. check /.next/static/chunks/app/[...slug]/page-${hash}.js
  5. There is no //# sourceMappingURL=page-${hash}.js.map string

Expected Result

//# sourceMappingURL=page-${hash}.js.map should be in the static files.

Actual Result

server:
image

client:
image

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 May 24, 2024
@github-actions github-actions bot added the Package: nextjs Issues related to the Sentry Nextjs SDK label May 24, 2024
@lforst
Copy link
Member

lforst commented May 27, 2024

Hi, we currently set the devtool option for webpack to hidden-source-map on the client which will remove that comment. I don't see any option in your configuration though that would indicate that you are generating sourcemaps yourself. Are we stomping your options somehow?

@aacheblukov
Copy link
Author

Hey @lforst! Thank you for the response! Sourcemaps are generated by nextjs by default for the development and it allows you to extend this behavior for the produciton build with productionBrowserSourceMaps flag. As you can see, I have this flag for next.config.js that is set up to true:
productionBrowserSourceMaps: true

https://nextjs.org/docs/app/api-reference/next-config-js/productionBrowserSourceMaps
I tested the prod build without withSentryConfig wrapper exporting the pure nextConfig and sourcemaps are present there.

@lforst
Copy link
Member

lforst commented May 29, 2024

I think I get what you're saying. I opened a PR to fix!

@AbhiPrasad
Copy link
Member

Fix released with https://github.com/getsentry/sentry-javascript/releases/tag/8.7.0 - please give it a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nextjs Issues related to the Sentry Nextjs SDK Type: Bug
Projects
Archived in project
3 participants