next.jssentry

TypeError: Cannot read properties of undefined (reading 'sentry') for Next.js site with Sentry


Trying to deploy a nextjs website with Sentry monitoring on hostinger. Sentry works when running locally, and the site doesnt crash, but it errors out and crashes when deployed on hostinger: console error screenshot

512-fd82f752a414c660.js:525 TypeError: Cannot read properties of undefined (reading 'sentry')
    at 164.1b37e5fe1265aae3.js:1:21471
    at Array.reduce (<anonymous>)
    at q (164.1b37e5fe1265aae3.js:1:21456)
    at n (164.1b37e5fe1265aae3.js:1:34922)
    at 164.1b37e5fe1265aae3.js:17:64552
    at oO (164.1b37e5fe1265aae3.js:17:67668)
    at oA (164.1b37e5fe1265aae3.js:17:63598)
    at 164.1b37e5fe1265aae3.js:17:63405
    at oP (164.1b37e5fe1265aae3.js:17:63412)
    at ov (164.1b37e5fe1265aae3.js:17:60278)
    at og (164.1b37e5fe1265aae3.js:17:58850)
    at S (164.1b37e5fe1265aae3.js:25:1364)
    at MessagePort.T (164.1b37e5fe1265aae3.js:25:1894)

nowhere in my code is .sentry called on any object. This is what my sentry.client.config.ts looks like


Sentry.init({
    dsn: "https://c14ecceb9e4b2cb37fcf625c50cb91db@o4508458061332480.ingest.us.sentry.io/4508458063233024",

    integrations: [
        Sentry.replayIntegration(),
        Sentry.feedbackIntegration({
            // Additional SDK configuration goes in here, for example:
            colorScheme: "dark",
        }),
    ],

production, or use tracesSampler for greater control.
    tracesSampleRate: 1,

while
    replaysSessionSampleRate: 1.0,
    replaysOnErrorSampleRate: 1.0,
    debug: false,
});

screenshot for at 164.1b37e5fe1265aae3.js:1:21471 in dev tools sources


Solution

  • This is potentially caused by the reactComponentAnnotation option of the Sentry SDK in your next.config.js. It appends properties to components and if the properties are iterated either by a library or your own code it may sometimes lead to errors.