Sentry "undefined is not an object ..."

Hi Guys,

I tried integrating Sentry into our app and I’m currently stuck with this error:
undefined is not an object (evaluating ‘global.document.addEventListener’)

Here’s a snippet of my code:
App.js

import * as Sentry from 'sentry-expo';
import Constants from 'expo-constants';

Sentry.init({
  dsn: 'my-dsn-here',
  enableInExpoDevelopment: true,
  debug: true
});
Sentry.setRelease(Constants.manifest.revisionId);

App.json:

    "hooks": {
      "postPublish": [
        {
          "file": "sentry-expo/upload-sourcemaps",
          "config": {
            "organization": "org-name-here",
            "project": "projectnamehere",
            "authToken": "my-token-here"
          }
        }
      ]
    }

SDK Version: 35
Platforms(Android/iOS/web/all): Android/iOS

Appreciate any help!
Thanks!
-Ken

I don’t see any problem because I’m using the exact same code as you, and mine works.

Can you try removing Sentry.setRelease(Constants.manifest.revisionId);?

In the docs:

Note that the revisionId is not available in the manifest when running in development mode (using Expo CLI), defaulting to undefined.

Hi @siddemo,

Still the same error removing
Sentry.setRelease(Constants.manifest.revisionId);

Does this still happen after clearing your cache (expo start -c)? And I take it you’re using the latest sentry-expo?

Even I am getting similar issue while upgrading the expo version to v35
undefined is not an object (evaluating '_sentryExpo.default.captureException')

Yep tried expo start -c already still the same.
Currently using "sentry-expo": "^2.0.1"

I’m unsure. Sentry works on my app, using the exact same code as you posted.

I’ll post my package.json below so you can make adjustments to yours and see if it works:

package.json

  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "@expo/vector-icons": "^10.0.5",
    "@shoutem/ui": "^0.24.1",
    "expo": "^35.0.0",
    "expo-asset": "^7.0.0",
    "expo-font": "^7.0.0",
    "expo-web-browser": "^7.0.0",
    "react": "16.8.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-35.0.0.tar.gz",
    "react-native-gesture-handler": "~1.3.0",
    "react-native-linear-gradient": "^2.5.4",
    "react-native-reanimated": "^1.1.0",
    "react-native-svg": "^9.5.3",
    "react-navigation": "^3.11.1",
    "react-redux": "^6.0.1",
    "redux": "^4.0.1",
    "redux-persist": "^5.10.0",
    "redux-thunk": "^2.3.0",
    "sentry-expo": "~2.0.0"
  },
  "devDependencies": {
    "babel-preset-expo": "^7.0.0",
    "jest-expo": "^35.0.0"
  },

I found the solution to the issue I was facing. The sentry new version 2.0.1 uses setUser instead of setUserContext in 1.13.0. so on changing the method name, this issue got solved for me

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.