sentry-javascript: "mod.require is not a function" Error after upgrading from 5.23.0 to >=5.24.0

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • other:

Version:

>=5.24.0

Description

Hello, we use Sentry for our Serverless applications which use NestJS and the nest-raven library that implements an interceptor to catch the errors and report them to Sentry.io and everything is bundled using Webpack. After we upgraded from 5.23.0 to the last version 5.26.0 we noticed that when an exception happens we receive an Internal Server Error and the original Exception is not reported to Sentry.io because it is the Sentry library that is having problems. The backend logs we have are:

  | 2020-10-13T14:51:20.131-04:00 | TypeError: mod.require is not a function
-- | -- | --
  | 2020-10-13T14:51:20.131-04:00 | at dynamicRequire (/var/task/src/adapters/graphql/handler.js:79802:16)
  | 2020-10-13T14:51:20.131-04:00 | at /var/task/src/adapters/graphql/handler.js:79860:39
  | 2020-10-13T14:51:20.131-04:00 | at Array.forEach (<anonymous>)
  | 2020-10-13T14:51:20.131-04:00 | at extractNodeRequestData (/var/task/src/adapters/graphql/handler.js:79845:10)
  | 2020-10-13T14:51:20.131-04:00 | at Module.parseRequest (/var/task/src/adapters/graphql/handler.js:131937:61)
  | 2020-10-13T14:51:20.131-04:00 | at RavenInterceptor.captureGraphQLException (/var/task/src/adapters/graphql/handler.js:645524:42)
  | 2020-10-13T14:51:20.131-04:00 | at Sentry.withScope (/var/task/src/adapters/graphql/handler.js:645514:45)
  | 2020-10-13T14:51:20.131-04:00 | at Hub.withScope (/var/task/src/adapters/graphql/handler.js:654823:13)
  | 2020-10-13T14:51:20.131-04:00 | at callOnHub (/var/task/src/adapters/graphql/handler.js:13438:28)
  | 2020-10-13T14:51:20.131-04:00 | at Module.withScope (/var/task/src/adapters/graphql/handler.js:13572:5)

After analyzing the bundle we noticed that the it happens in the dynamicRequire function specifically when it’s called from packages/utils/src/node.ts line 93 which was introduced in version 5.24.0.

Checking the stacktrace it happens when Handlers.parseRequests is called from the Nest-Raven library we use

So far the workaround is to keep using @sentry/node@5.23.0 where the error does not happen.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 13
  • Comments: 20 (4 by maintainers)

Most upvoted comments

@rbisol This has been open and reproducible nearly three months. Downgrading the package version not an appropriate solution. Any updates?

@rbisol Any updates from Sentry on this?

Hi, we have encountered the same issue, the only workaround for us was to downgrade to 5.22.0. Any progress on a problem yet?

"@sentry/node": "6.0.3",

#3210 wasn’t released in 6.0.3. We’ll have to wait for 6.0.4.

@rbisol Here’s the repo https://github.com/kamilchlebek/sentry-express-demo

Run: npm start and provide environment variable SSR_SENTRY_DSN. Open localhost:4500/debug-sentry to trigger an error.

I think it’s caused by webpack bundling, have a look at this thread: https://github.com/getsentry/sentry-javascript/pull/2515

@sergio-dreamcode - Can you please open a separate issue, specifically about the DB integrations? Thanks.

@sergio-dreamcode I think you’ve mentioned wrong “Kamil” 😃

-> @kamilogorek

PS. 6.0.4 works for me too.

Hi @kamilchlebek we’ve been using the latest upgrade since 6.0.4 and it worked like a charm. Thanks again.

Since the fix was released we added Sentry performance tracing to our applications and it worked perfectly. We wanted to improve our tracing by adding the Postgres tracing integration to the backend.

We found that the same issue happens in the tracing system but not in the same way as the original bug was in this issue, it does not crash the library either but prevents Postgres tracing to work. We are using version 6.2.0.

When adding the Postgres tracing integration as the documentation recommends, after testing we noticed that the Postgres tracing was not working and found the next error in our logs:

ERROR Sentry Logger [Error]: Postgres Integration was unable to require `pg` package.

After checking the Postgres integration source (same happens for other database integrations) I found that it calls to the dynamicRequire util which in turn calls mod.require.

In order to validate that we were having the same error I cloned a local copy of sentry-javascript and added an error log to display the Javascript exception and linked this local copy to our project. These were the logs:

ERROR Sentry Logger [Error]: Postgres Integration was unable to require `pg` package.
ERROR Sentry Logger [Error]: TypeError: mod.require is not a function

The code that I modified to get the TypeError: mod.require is not a function error was in the postgres.ts file:

...
  public setupOnce(_: (callback: EventProcessor) => void, getCurrentHub: () => Hub): void {
    let client: PgClient;

    try {
      const pgModule = dynamicRequire(module, 'pg') as { Client: PgClient };
      client = pgModule.Client;
    } catch (e) {
      logger.error('Postgres Integration was unable to require `pg` package.');
      logger.error(e); // <<<< the line I added to validate
      return;
    }
...

Should I open a new issue or we could re-open this one?

6.0.4 is coming in few moments. Thanks for your patience.

setup “@sentry/node”: “6.0.2”, get the same issue

Hi all, we’re running sentry in nodejs angular universal project and we also get this error (in 5.24 and higher versions). I’ll be glad to help, if If you need me to try anything.

I tried using import as in https://github.com/getsentry/sentry-electron/issues/92#issuecomment-453534680 but it doesn’t work

import { init } from '@sentry/node/dist/index';
import * as Sentry from '@sentry/node';

Any other ideas?