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

[Self-hosted] Cannot read properties of undefined (reading 'getInitialProps') #8792

Closed
3 tasks done
KeithChou opened this issue Aug 11, 2023 · 3 comments · Fixed by #8794
Closed
3 tasks done

[Self-hosted] Cannot read properties of undefined (reading 'getInitialProps') #8792

KeithChou opened this issue Aug 11, 2023 · 3 comments · Fixed by #8794

Comments

@KeithChou
Copy link

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Which SDK are you using?

@sentry/browser

SDK Version

7.62.0

Framework Version

Next 13.4.11

Link to Sentry event

No response

SDK Setup

Sentry.init({
dsn: dsn,
// Replay may only be enabled for the client-side
enabled: true,
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 0.1

// Capture Replay for 10% of all sessions,
// plus for 100% of sessions with an error

// ...

// Note: if you want to override the automatic release value, do not set a
// release value here - use the environment variable SENTRY_RELEASE, so
// that it will also get attached to your source maps
})

Steps to Reproduce

next.config.js file
this is the configuration content related to the sentry

/** @type {import('next').NextConfig} */
const withPlugins = require('next-compose-plugins')
const { createPlugin } = require('./build/next/createPlugin.ts')

const nextConfig = {
  // ...
  sentry: {
    hideSourceMaps: true,
    widenClientFileUpload: true
  },
  distDir: 'dist',
  // ..
}

module.exports = withPlugins(createPlugin(), nextConfig)

createPlugin file

const { withSentryConfig } = require('@sentry/nextjs')
const { configSentryWebpackPlugin } = require('../plugin/configSentryWebpackPlugin.ts')

exports.createPlugin = () => {
  const plugins = []
  plugins.push([withSentryConfig(configSentryWebpackPlugin())])

  return plugins
}

configSentryWebpackPlugin file

exports.configSentryWebpackPlugin = () => {
  return {
    org: process.env.SENTRY_ORG,
    url: process.env.SENTRY_URL,
    project: process.env.SENTRY_PROJECT,
    authToken: process.env.SENTRY_AUTH_TOKEN,
    silent: true, // Suppresses all logs,
    // For all available options, see:
    // https://github.com/getsentry/sentry-webpack-plugin#options.
  }
}

sentry.config.tsfile


Sentry.init({
  dsn: `dsn`,
  // Replay may only be enabled for the client-side
  enabled: true,
  // Set tracesSampleRate to 1.0 to capture 100%
  // of transactions for performance monitoring.
  // We recommend adjusting this value in production
  tracesSampleRate: 0.1

  // Capture Replay for 10% of all sessions,
  // plus for 100% of sessions with an error

  // ...

  // Note: if you want to override the automatic release value, do not set a
  // `release` value here - use the environment variable `SENTRY_RELEASE`, so
  // that it will also get attached to your source maps
})

sentry.client.config.ts, sentry.server.config.ts, sentry.edge.config.ts file

import './sentry.config'

.env: here is some sentry env

SENTRY_ORG = test
SENTRY_URL = url
SENTRY_PROJECT = project
SENTRY_AUTH_TOKEN = token

and when I run pnpm build, it will occur some error like this
image

I found there is a solution at #5978 and #5984. Unfortunately, it does not work for me. I don't know if is there any difference between saas and self-hoisted.

Expected Result

upload the sourcemap successfully.

Actual Result

image
@lforst
Copy link
Member

lforst commented Aug 11, 2023

Hi, this seems like a bug in the SDK. My questions:

  • Is there more in the build output you can share?
  • Can you try simply wrapping your config with withSentryConfig instead of passing it to next-compose-plugins
  • Do you in some place define the default export as undefined?

lforst added a commit that referenced this issue Aug 11, 2023
Fixes #8792

In #8792 a user reports that we read `getInitialProps` from `undefined`. The only place where we read `getInitialProps` is in the page wrapper template. As a fix we simply check for its existence before accessing the field.
@seeARMS
Copy link

seeARMS commented Aug 14, 2023

This is still happening for me, even with the above change in (on @sentry/nextjs@7.64.0).

Here's a URL of it in action (the two iFrame subscribe boxes): https://news.kiwistand.com/subscribe

Using getServerSideProps in the page, with NextJS 12.3.1.

The page in question is a rewritten route, if that helps. It's rewritten from /[blogName]/embed to /[blogName]/subscribe within the next.config.js file, and the page in question is located at /pages/[blogName]/subscribe.tsx.

What's strange is this is only happening when the page is in an iFrame. When it's viewed in a regular URL, there's no exception.

@lforst
Copy link
Member

lforst commented Aug 16, 2023

@seeARMS I can't see any errors on the page you shared. Do I need to put news.kiwistand.com/subscribe into an iframe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants