Skip to content

TypeError: Cannot read properties of undefined (reading '_sentryTransaction') #5864

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

Closed
3 tasks done
cmorbitzer opened this issue Sep 30, 2022 · 14 comments · Fixed by #5866
Closed
3 tasks done

TypeError: Cannot read properties of undefined (reading '_sentryTransaction') #5864

cmorbitzer opened this issue Sep 30, 2022 · 14 comments · Fixed by #5866

Comments

@cmorbitzer
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/nextjs

SDK Version

7.14.0

Framework Version

12.3.0

Link to Sentry event

https://sentry.io/organizations/craft-codery/issues/3635175907/?project=4503904394412032&query=is%3Aunresolved

Steps to Reproduce

  1. Installed Sentry for Next.JS using the instructions at https://docs.sentry.io/platforms/javascript/guides/nextjs/
  2. Used the setup wizard, as per instructions
  3. Wrapped my API routes, as per instructions
  4. Ran my app, visited the homepage, immediately get the error TypeError: Cannot read properties of undefined (reading '_sentryTransaction')

Expected Result

No error

Actual Result

Uncaught TypeError: Cannot read properties of undefined (reading '_sentryTransaction')
  at getTransactionFromRequest(node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:17:14)
  at <unknown>(node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:67:30)
  at bound(node:domain:421:15)
  at runBound(node:domain:432:12)
  at Object.callTracedServerSideDataFetcher(node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:128:5)
  at Function.getInitialProps(node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryServerSideDocumentGetInitialProps.js:33:27)
  at Object.<anonymous>(node_modules/next/dist/shared/lib/utils.js:75:33)
  at Generator.next(<anonymous>)
  at asyncGeneratorStep(node_modules/@swc/helpers/lib/_async_to_generator.js:23:28)
  at _next(node_modules/@swc/helpers/lib/_async_to_generator.js:12:17)
@tayloraucoin
Copy link

Getting the same issue when setting up on Next.js

@daniellin215
Copy link

Same on my setup

@lforst
Copy link
Contributor

lforst commented Oct 1, 2022

Hi everybody. Thanks for reporting this issue! This bug is caused by a pretty new feature we only roll out per default when installing the SDK via the @sentry/wizard.

In the meanwhile and to get your apps working again you can simply set the autoInstrumentServerFunctions option to false in your Next.js config.

We'll try to get a fix out for this asap.

@daniellin215
Copy link

Hey @lforst this would mean we need to manually wrap our api routes right? If we set that setting to false atm.

@lforst
Copy link
Contributor

lforst commented Oct 1, 2022

Hey @lforst this would mean we need to manually wrap our api routes right? If we set that setting to false atm.

Correct!

@lforst
Copy link
Contributor

lforst commented Oct 1, 2022

@daniellin215 Just to help me debug this. Do you have a getInitialProps method defined in pages/_document.ts?

@daniellin215
Copy link

daniellin215 commented Oct 1, 2022

@lforst sorry formatting is off, on mobile atm.

`import Document from "next/document";

export default class MyDocument extends Document {
static async getInitialProps(ctx: any) {
const initialProps = await Document.getInitialProps(ctx);
return {
...initialProps,
styles: <>{initialProps.styles}</>,
};
}
}`

@lforst
Copy link
Contributor

lforst commented Oct 1, 2022

@daniellin215 Thank you!

Can anybody reproduce the error with next build && next start, or just with next dev?

@lforst
Copy link
Contributor

lforst commented Oct 3, 2022

We released a patch that should fix this error. Let me know if you encounter any more problems!

@flowen
Copy link

flowen commented Jan 11, 2023

Strangely, this exact error started appearing when we installed 7.14.1 which should contain the fix. Updating to 7.30 (current latest) didn't work so we rolled back to 7.12.1 which doesn't cause any error for us @lforst

@lforst
Copy link
Contributor

lforst commented Jan 11, 2023

@flowen what is the exact error you're getting?

@flowen
Copy link

flowen commented Jan 11, 2023

@lforst

TypeError: Cannot read properties of undefined (reading '_sentryTransaction')
  at getTransactionFromRequest(/var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:22:14)
  at ? (/var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:72:32)
  at bound(node:domain:421:15)
  at runBound(node:domain:432:12)
  at ? (/var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:150:7)
  at ? (/var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryGetServerSideProps.js:36:63)
  at getServerSideProps(/var/task/.next/server/pages/profile/[userId]/[subPage].js:70:90)
  at ? (/var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:39:33)
  at ? (/var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:137:38)
  at bound(node:domain:421:15)
  at runBound(node:domain:432:12)
  at ? (/var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/wrapperUtils.js:150:7)
  at ? (/var/task/node_modules/@sentry/nextjs/cjs/config/wrappers/withSentryGetServerSideProps.js:36:63)
  at Object.renderToHTML(/var/task/node_modules/next/dist/server/render.js:490:26)
  at processTicksAndRejections(node:internal/process/task_queues:96:5)
  at async doRender(/var/task/node_modules/next/dist/server/base-server.js:906:38)
  at async cacheEntry.responseCache.get.isManualRevalidate.isManualRevalidate(/var/task/node_modules/next/dist/server/base-server.js:1011:28)
  at ? (async /var/task/node_modules/next/dist/server/response-cache.js:69:36)

@lforst
Copy link
Contributor

lforst commented Jan 11, 2023

@flowen are you by chance calling getServerSideProps from a different place and not passing req and res objects?

@flowen
Copy link

flowen commented Jan 12, 2023

@lforst you're right, we import getServerSideProps to profile/[userId]/[subPage].js from profile/[userId], but we do pass the whole context object down with it as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants