Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"mod.require is not a function" Error after upgrading from 5.23.0 to >=5.24.0 #2971

Closed
4 of 9 tasks
sergio-dreamcode opened this issue Oct 13, 2020 · 20 comments · Fixed by #3210
Closed
4 of 9 tasks

Comments

@sergio-dreamcode
Copy link

sergio-dreamcode commented Oct 13, 2020

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/[email protected] where the error does not happen.

@rodolfoBee
Copy link
Member

@sergio-dreamcode can you provide a simple repro app?

@kamilchlebek
Copy link

@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: #2515

@sergio-dreamcode
Copy link
Author

Thanks for the sample repo @kamilchlebek. As you mentioned it is possible to be related with webpack by checking #2515. That PR removed the usage of dynamicRequire however it was introduced again as part of 5.24.0 #2820

@ybrodsky
Copy link

ybrodsky commented Nov 2, 2020

@sergio-dreamcode wil #2515 be re-instated? Or was the #2820 reintroduction intentional?

@sergio-dreamcode
Copy link
Author

wil #2515 be re-instated? Or was the #2820 reintroduction intentional?

@ybrodsky I'm not sure, I checked in #2515 that removed dynamicRequire but in #2524 it was restored only for hooks so it was not breaking anything. The change in #2820 seems to be related with hooks but this time is breaking webpack builds as no events can be reported causing the mod.require error.

@ch1ller0
Copy link

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?

@dvins
Copy link

dvins commented Dec 17, 2020

@rbisol Any updates from Sentry on this?

@RatkoR
Copy link

RatkoR commented Jan 4, 2021

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 getsentry/sentry-electron#92 (comment) but it doesn't work

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

Any other ideas?

@RatkoR
Copy link

RatkoR commented Jan 5, 2021

To reproduce this, take angular universal zip from https://angular.io/guide/universal and add @sentry/node to it.

A request to /debug-sentry logs a mod.require is not a function error and not My first Sentry error.

@sergio-dreamcode
Copy link
Author

@rbisol I think we should remove the Needs Reproduction tag because @kamilchlebek already provided a repository to reproduce the issue.

@dvins
Copy link

dvins commented Jan 5, 2021

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

@mihanizm56
Copy link

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

@mihanizm56
Copy link

mihanizm56 commented Jan 25, 2021

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

figured out that the problem is in package
"@sentry/tracing": "6.0.2",

when adding app.use(Sentry.Handlers.tracingHandler()) to server code from the docs

@lobsterkatie
Copy link
Member

Hi, all. This should be fixed once #3210 is released. Please let me know if you're still running into trouble.

@mihanizm56
Copy link

mihanizm56 commented Jan 31, 2021

"@sentry/node": "6.0.3",
"@sentry/react": "6.0.3",
"@sentry/tracing": "6.0.3",
"webpack": "4.43.0
 node 12.14

import * as Tracing from '@sentry/tracing';
import * as Sentry from '@sentry/node';

the same issue
"e.required is not a function" in the prod build and "mod.require is not a function" in dev build

image
image

@RatkoR
Copy link

RatkoR commented Jan 31, 2021

"@sentry/node": "6.0.3",

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

@kamilogorek
Copy link
Contributor

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

@sergio-dreamcode
Copy link
Author

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?

@kamilchlebek
Copy link

@sergio-dreamcode I think you've mentioned wrong "Kamil" :)

-> @kamilogorek

PS. 6.0.4 works for me too.

@lobsterkatie
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants