sentry-javascript: [ error ] ./node_modules/@sentry/node/esm/integrations/console.js Module not found: Can't resolve 'console' in - Sentry in Nextjs
Package + Version
@sentry/browser^5.11.0@sentry/node^5.11.0nodev12.7.0
Description
I have a nextjs application and I followed this tutorial provided by nextjs community. The problem is after building and running my app it gives this error:
[ error ] ./node_modules/@sentry/node/esm/integrations/console.js
Module not found: Can't resolve 'console' in '/.../node_modules/@sentry/node/esm/integrations'
I rebuild my app and removed my yarn lock and build folder but nothing happened! Although I have the directory in my node_modules!
The error is when I’m trying to import Sentry like this :
import * as Sentry from '@sentry/node';

About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 18
- Comments: 24 (1 by maintainers)
For anyone using the latest update with
@sentry/nextjsafter running the new setup (which simplified things quite a bit), change all of your imports fromimport * as Sentry from '@sentry/node';toimport * as Sentry from '@sentry/nextjs';.Add:
to the
next.config.js@5tormTrooper Not sure if this will help, but I forgot to add the () to the require statement:
const withSourceMaps = require('@zeit/next-source-maps')()As you can tell, all referenced issues has been already somehow resolved by changing dev config. I’m not able to provide any specific fix if I’m not presented with a concrete problem and repro case.
Folllowed the suggestion exactly and I’m still having this issue.
Just in case anyone’s not clear exactly how to add the fix to your
next.config.jshere’s how I did it:and to @vpotis point below, you need to add the dependancy
@sentry/browserto yourpackage.jsonIf you have this line:
Then you also need to install
@sentry/browser. The error is a little misleading…@afsanefda I still have this issue after clean
node_modulesremoveyarn.lockand having@zeit/next-source-maps": "0.0.4-canary.1as dependency… Did you do any other thing that could have fixed the issue?I think the problem was the version of
@zeit/next-source-mapswhich I changed to:@zeit/next-source-maps": "0.0.4-canary.1.Then I cleaned
node_modulesand removedyarn.lockand rebuild! It is working now!An we reopen this issue? I tried updating all packages and can’t figure out how to resolve it.
I faced same issue after upgrading Next.js from ‘9.1.6’ to ‘9.3.5’. After some debugging i figured that ‘@sentry/node’ somehow ended up in the client bundle. It seems that this line stopped working all of a sudden.
if (!isServer) { config.resolve.alias['@sentry/node'] = '@sentry/browser'; }