I've run into a nasty config issue in a project using Next.js 14.2.5 (pages router), Jest, and Sentry. I am upgrading from Sentry v7 to v8, and any time that I import from @sentry/nextjs, running Jest tests immediately results in a cryptic error:
TypeError: Cannot read properties of undefined (reading 'events')
I've run into a nasty config issue in a project using Next.js 14.2.5 (pages router), Jest, and Sentry. I am upgrading from Sentry v7 to v8, and any time that I import from @sentry/nextjs, running Jest tests immediately results in a cryptic error:
TypeError: Cannot read properties of undefined (reading 'events')
Share
Improve this question
edited Mar 11 at 15:43
Joshua Miles
asked Mar 11 at 15:42
Joshua MilesJoshua Miles
817 bronze badges
1 Answer
Reset to default 0While it is presenting differently, I believe the error is the same one reported in this GitHub Issue, and the work-around proposed there worked for me as well. I added the following to my jest.config.js
:
moduleNameMapper: {
'@sentry/nextjs': '\<rootDir\>/node_modules/@sentry/nextjs',
},
Cross-posting here with the specific error message I encountered so that it can be found a little more easily by the next person