next.js: with-sentry-simple example doesn't work in server although it says it does.
The readme.md of the example states it works on the server-side.
This is a simple example showing how to use Sentry to catch & report errors on both client + server-side.
However, The example using @sentry/browser which doesn’t work on the server (node environment)
Where can I simple alternative for using sentry on the server-side? the other example with-sentry seems too complicated.
for some reason import @sentry/node (latest version) in a simple nextjs project is met with an error
[ wait ] compiling ...
[ error ] ./node_modules/@sentry/node/esm/integrations/console.js
Module not found: Can't resolve 'console' in '/Users/lirancohen/Projects/amp-app/node_modules/@sentry/node/esm/integrations'
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 19 (9 by maintainers)
Some notes on how to get this working:
_app.jsis not client-side only, it it called on the server as well (you can verify this yourself with some console logs). Thus @shuhei-tagawa’s idea above to havenext.config.jsswap out@sentry/nodemakes sense_document.jsis unnecessary._app.jswill run on the server andSentry.initinstalls its own hooks forunhandledRejectionanduncaughtException_error.js. They are passed togetInitialProps({ err }), except in the case of https://github.com/zeit/next.js/issues/8592. Thus, within_error.js, you can useSentry.captureException. Here are the cases I’ve found where Next.js will handle the errors:getInitialPropson the servergetInitialPropson the client (in hydration or navigation)const env = process.env; const v = env.VARwill throw on the client, becauseprocessdoes not exist)Note that
@sentry/browserwill still run in a Node environment, it just won’t hook itself in as well as@sentry/nodewould.I’ll see if I can make a PR to the example if I get time. @leerob maybe we can collaborate. I want there to be a simple way to integrate Next.js with Sentry as well, that doesn’t involve a custom server.
For people looking to implement Sentry with Next.js, make sure to check out https://github.com/UnlyEd/next-right-now
Interesting parts are:
Try to put below on
next.config.jsas the examplewith-sentry.@robertkibet I’m facing the same as .sentryclirc file is added in .gitignore and vercel build is getting failed cuz there is not auth.token there.
now I’ve added env var on vercel for sentry auth token and it works well.
@5tormTrooper This error usually occurs when you did not wrap your custom webpack config in the
withSourceMapfunction provided from the@zeit/next-source-mapspackage.https://github.com/UnlyEd/next-right-now/blob/master/next.config.js#L8
Currently only the
0.0.4-canary.1version of the package works.@5tormTrooper I don’t know when you looked at NRN, and you’re right it’s opinionated but I’m currently working on different “presets”, the goal being to release different presets with different built-in features, and eventually end up with a “simple” preset with the minimal stuff for easier re-use and avoid “too much opinions”.
Read more at https://unlyed.github.io/next-right-now/concepts/presets
I’ve had my hands full due to COVID-19 crisis, but I’ll definitely release simpler presets at some point.