Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NextJS 14 with Sentry 8.48.0: [RouterEvents not found] #14928

Answered by ahetawal-p
ahetawal-p asked this question in Q&A
Discussion options

Hello,
We just upgraded our sentry version to the latest release as of today.
And started seeing this issue in Jest tests.

TypeError: Cannot read properties of undefined (reading 'events')
at Object.<anonymous> (node_modules/@sentry/nextjs/src/client/routing/pagesRouterRoutingInstrumentation.ts:19:50)
 at Object.<anonymous> (node_modules/@sentry/nextjs/build/cjs/client/routing/nextRoutingInstrumentation.js:5:43)
 at Object.<anonymous> (node_modules/@sentry/nextjs/build/cjs/client/browserTracingIntegration.js:4:36)
 at Object.<anonymous> (node_modules/@sentry/nextjs/build/cjs/client/index.js:12:35)
 at Object.<anonymous> (node_modules/@sentry/nextjs/build/cjs/index.client.js:3:15)
 at Object.<anonymous> (src/context/CurrentUserStateProvider.tsx:[25](https://github.com/semper-aviation/goodwin_web/actions/runs/12655302982/job/35265273114#step:5:26):17)
 at Object.<anonymous> (src/components/layout/appShell/Navbar.tsx:18:35)
 at Object.<anonymous> (src/components/layout/appShell/Navbar.test.tsx:11:56)

Since we dont have next/router usage anymore move to app dir with nextjs, what can we do to fix these errors.
I was not able to find any documentation on mocking this or get rid of this ?

You must be logged in to vote

No I am not.
Only thing after migrating to NextJS14 was this.

jest.mock('next/navigation', () => ({
 usePathname: jest.fn(),
}))
;(usePathname as jest.Mock).mockImplementation(() => '/')

However for my test to pass I had to add this to work now...

jest.mock('@sentry/nextjs', () => ({
 browserTracingIntegration: jest.fn().mockReturnValue({}),
}))

Replies: 1 comment 1 reply

Comment options

Hi, are you mocking the Next.js router in any way?

You must be logged in to vote
1 reply
Comment options

No I am not.
Only thing after migrating to NextJS14 was this.

jest.mock('next/navigation', () => ({
 usePathname: jest.fn(),
}))
;(usePathname as jest.Mock).mockImplementation(() => '/')

However for my test to pass I had to add this to work now...

jest.mock('@sentry/nextjs', () => ({
 browserTracingIntegration: jest.fn().mockReturnValue({}),
}))
Answer selected by ahetawal-p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /