question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Sentry.Init: 'Cannot read property 'bind' of undefined' when running jest

See original GitHub issue

Environment

How do you use Sentry? Sentry SaaS (sentry.io)

Which SDK and version? "@sentry/react-native": "^2.5.0",

Steps to Reproduce

  1. Run tests with jest

Expected Result

Tests should run fine

Actual Result

Get this error:

  ● Test suite failed to run

    TypeError: Cannot read property 'bind' of undefined

      16 |     const appBuild = RNDeviceInfo.getBuildNumber();
      17 |
    > 18 |     Sentry.init({
         |            ^
      19 |       dsn:
      20 |         '...',
      21 |       ignoreErrors,

      at getNativeFetchImplementation (node_modules/@sentry/browser/src/transports/fetch.ts:73:20)
      at new FetchTransport (node_modules/@sentry/browser/src/transports/fetch.ts:84:72)
      at ReactNativeBackend._setupTransport (node_modules/@sentry/react-native/src/js/backend.ts:87:12)
      at ReactNativeBackend.BaseBackend (node_modules/@sentry/core/src/basebackend.ts:72:28)
      at new ReactNativeBackend (node_modules/@sentry/react-native/src/js/backend.ts:18:5)
      at ReactNativeClient.BaseClient (node_modules/@sentry/core/src/baseclient.ts:88:21)
      at new ReactNativeClient (node_modules/@sentry/react-native/src/js/client.ts:22:5)
      at initAndBind (node_modules/@sentry/core/src/sdk.ts:21:18)
      at Object.init (node_modules/@sentry/react-native/src/js/sdk.ts:82:3)
      at new ErrorHandler (src/client-blocks/helpers/ErrorHandler.ts:18:12)

This error started happening after I upgraded from 2.4.2 to 2.5.0. I setup sentry like this:

Sentry.init({
      dsn: '...',
      ignoreErrors,
      enableNative:
        typeof process?.env?.JEST_WORKER_ID !== 'undefined' ? false : true,
      release: `${bundleId}@${appVersion}+${appBuild}`,
    });

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
svenlombaertcommented, Jun 16, 2021

@svenlombaert When running jest tests, you would now have to pass NoopTransport to Sentry.init under transport. You should be able to import it from @sentry/react. Although this will cause errors to not be sent (as the transport is a No-Op) I assume that should be fine unless you’re also testing your Sentry integration?

This seems to work and is exactly what I need, thanks! Had to import NoopTransport from @sentry/core though. What’s the default value of the transport param actually?

1reaction
jennmuengcommented, Jun 15, 2021

@svenlombaert When running jest tests, you would now have to pass NoopTransport to Sentry.init under transport. You should be able to import it from @sentry/react. Although this will cause errors to not be sent (as the transport is a No-Op) I assume that should be fine unless you’re also testing your Sentry integration?

Read more comments on GitHub >

github_iconTop Results From Across the Web

jest: Test suite failed to run, TypeError: Cannot read property ...
Try to re-install both jest and jest babel last versions ... Test suite failed to run, TypeError: Cannot read property 'bind' of undefined....
Read more >
Troubleshooting for React - Sentry Documentation
If your application started to misbehave because of performing additional OPTIONS requests, it is most likely an issue with unwanted sentry-trace request ......
Read more >
typeerror: cannot read properties of undefined ... - You.com
Reason : As there is no named export of ReactDOM from "react-dom", it is not imported and the reference will be undefined. So,...
Read more >
@sentry/react | Yarn - Package Manager
Important: This documentation covers modern versions of Yarn. For 1.x docs, see classic.yarnpkg.com. Yarn.
Read more >
TypeError: Cannot read property 'bind' of undefined
I am facing some issues with running detox test with jest . The error I am getting is: detox test -c ios detox[47286]...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found