sentry-javascript: @sentry/nextjs not working on server
- Review the documentation: https://docs.sentry.io/
 - Search for existing issues: https://github.com/getsentry/sentry-javascript/issues
 - Use the latest release: https://github.com/getsentry/sentry-javascript/releases
 - Provide a link to the affected event from your Sentry account
 
Package + Version
-  
@sentry/browser -  
@sentry/node -  
raven-js -  
raven-node(raven for node) - other: nextjs
 
Version:
6.7.1
Description
When I scafold a nextjs app (using nx workspaces, but probably unrelated) and add sentry to it, the frontend works just fine, but running next dev results in pages/api/* routes not logging to sentry. I do use the withSentry wrapper around my handlers, but it appears that Sentry.init never gets called despite sentry.server.config.js being configured. Calling it manually right outside the handler fixes it, so it’s definitely got to do with the cli not calling init. I am guessing the init gets called during webpack builds which is configured to only run in production (I dont want to upload source maps for local dev).
About this issue
- Original URL
 - State: closed
 - Created 3 years ago
 - Reactions: 1
 - Comments: 15 (2 by maintainers)
 
Some more info here: It will load the 2nd time it runs, suggesting the cache creation timing is different. I am using 11.0.1-canary.2 since it fixed some blocking issues.
Just wanted to add, v6.8.0 does not solve this problem.
Same issue here. Just tried upgrading to next 11. I’ve only tried starting my nextjs app in dev mode so far. I get the same log messages as @ckychris, reproduced here:
My app does indeed start, and everything looks normal.
One thing to note: in dev mode, when
NODE_ENV !== 'production', i do not include the sentry webpack plugin. My full next.config.js looks like this:Edit: i also get this same error/warning when creating a production build and running the prod server via
npm run buildandnpm run start. I do not see the error during the build step. It only shows up the first time i try to load a page after building and starting the server.Hi, all.
There were two problems causing this, I believe, one of them fixed here (already released) and one of them fixed here (should be released tomorrow, as 6.10.0).
Once that release is published, can you all please try upgrading, and let us know if you’re still having trouble? I’m going to close this in the meantime, but please do reach out if you have further problems.
Thanks!
The error
Error: Cannot find module '/var/www/app/.next/server/sentry/initServerSDK.js'is a false-positive, it was explained here.