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.0
  • nodev12.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';

Screenshot from 2020-01-11 12-56-20

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 18
  • Comments: 24 (1 by maintainers)

Most upvoted comments

For anyone using the latest update with @sentry/nextjs after running the new setup (which simplified things quite a bit), change all of your imports from import * as Sentry from '@sentry/node'; to import * as Sentry from '@sentry/nextjs';.

Add:

if (!options.isServer) {
  config.resolve.alias['@sentry/node'] = '@sentry/browser'
}

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.js here’s how I did it:

const isServer = (config) => config.name === 'server';

module.exports = {
  webpack: (config) => {
    if (!isServer(config)) {
      config.resolve.alias['@sentry/node'] = '@sentry/browser';
    }
    return config;
  }
  //... other config
}

and to @vpotis point below, you need to add the dependancy @sentry/browser to your package.json

If you have this line:

if (!isServer) { config.resolve.alias['@sentry/node'] = '@sentry/browser'; }

Then you also need to install @sentry/browser. The error is a little misleading…

If you have this line:

if (!isServer) { config.resolve.alias['@sentry/node'] = '@sentry/browser'; }

Then you also need to install @sentry/browser. The error is a little misleading…

@afsanefda I still have this issue after clean node_modules remove yarn.lock and having @zeit/next-source-maps": "0.0.4-canary.1 as dependency… Did you do any other thing that could have fixed the issue?

I think the problem was the version of @zeit/next-source-maps which I changed to: @zeit/next-source-maps": "0.0.4-canary.1.

Then I cleaned node_modules and removed yarn.lock and 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'; }