Skip to content

Can't use withSentryConfig because it breaks NextJS  #9450

Closed
@leonardopiperai

Description

@leonardopiperai

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

7.70.0

Framework Version

@sentry/nextjs 7.70.0

Link to Sentry event

No response

SDK Setup

next.config

/** @type {import('next').NextConfig} */
const { withSentryConfig } = require('@sentry/nextjs')

const nextConfig = {
  reactStrictMode: true,
  serverRuntimeConfig: {
    buildEnv: process.env.BUILD_ENV
  },
  publicRuntimeConfig: {
    buildEnv: process.env.BUILD_ENV
  },
  images: {
    remotePatterns: [
      {
        protocol: 'https',
        hostname: '**'
      }
    ]
  }
}

module.exports = nextConfig

module.exports = withSentryConfig(module.exports, { silent: true })

sentry.client.config.js

import * as Sentry from '@sentry/nextjs'

const SENTRY_DSN = process.env.SENTRY_DSN || process.env.NEXT_PUBLIC_SENTRY_DSN
const SENTRY_ENVIRONMENT = process.env.SENTRY_ENVIRONMENT || process.env.ENVIRONMENT

Sentry.init({
  dsn: SENTRY_DSN,
  environment: SENTRY_ENVIRONMENT,
  tracesSampleRate: 0.1,
  debug: false,
  replaysOnErrorSampleRate: 0.1,
  replaysSessionSampleRate: 0.1,
  integrations: [
    new Sentry.Replay({
      maskAllText: true,
      blockAllMedia: true
    })
  ]
})

Steps to Reproduce

  1. Run next dev
  2. Console throws an error (see picture below)

Expected Result

Not to break the build

Actual Result

image

Some comments:

  • This error is fixed with version 7.20.1 the problem is that that version is imcompatible with my current Next version [email protected]
  • If I remove withSentryConfig everything works, but there is some problem with withSentryConfig wrapping the NextJS config

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: nextjsIssues related to the Sentry Nextjs SDK

    Type

    No type

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions