gatsby-plugin-sentry icon indicating copy to clipboard operation
gatsby-plugin-sentry copied to clipboard

ReferenceError: Sentry is not defined

Open rodrigogiraudo opened this issue 5 years ago • 2 comments

I Followed the documentation and can't manage to use this. I have in gatsby-config.js in plugins:[]

{
      resolve: 'gatsby-plugin-sentry',
      options: {
        dsn: MYURL,
        // Optional settings, see https://docs.sentry.io/clients/node/config/#optional-settings
        environment: 'staging',
        enabled: (() => ["production", "stage"].indexOf(process.env.NODE_ENV) !== -1)(),
        debug: true
        attachStacktrace: true,
      }
    },

I created the component ErrorBoundary as:

import React from 'react';

export default class ErrorBoundary extends React.Component {
  constructor(props) {
    super(props);
    this.state = { error: null };
  }

  componentDidCatch(error, errorInfo) {
    console.log('[Sentry][ErrorBoundary] - componentDidCatch - error: ', error, 'errorInfo', errorInfo);
    this.setState({ error });
    Sentry.configureScope(scope => {
      Object.keys(errorInfo).forEach(key => {
        scope.setExtra(key, errorInfo[key]);
      });
    });
    Sentry.captureException(error);
  }

  render() {
    return this.props.children;
  }
}

and in my rootWrapper.js I added to the nesting:

export default ({ element }) => {
  return (
    <StylesProvider injectFirst>
      <ThemeProvider theme={theme}>
        <Provider store={store}>
          <ErrorBoundary>
            <App element={element} />
          </ErrorBoundary>
        </Provider>
      </ThemeProvider>
    </StylesProvider>
  );
};

And when triggering an error I get:

ReferenceError: Sentry is not defined
ErrorBoundary.componentDidCatch
src/components/ErrorBoundary/index.js:11

rodrigogiraudo avatar Jan 08 '20 20:01 rodrigogiraudo

I think you are missing an import in your ErrorBoundary component. Try adding import Sentry from "gatsby-plugin-sentry"

runebakjacobsen avatar Jan 11 '20 21:01 runebakjacobsen

I added this and it works import * as Sentry from '@sentry/browser';

mmgolden avatar Jun 03 '20 14:06 mmgolden