Skip to content

Cannot read properties of undefined (reading 'context') #102

Open

Description

@hosseintalebi

I'm trying to use RollbarContext and it's giving me an error on its componentDidMount function as it's trying to access rollbar.options.payload.context (see here). Looking at the rollbar.options object, there's no payload.

image

This is how I'm using the <RollbarContext>:

const rollbarConfig = {
  accessToken: '<token>',
  environment: 'testenv',
};
...
    <Provider config={rollbarConfig}>
       <ErrorBoundary>
        <Router>
          <Route path={rootPath}>
            <Switch>
              {Object.entries(routes).map(([path, route]) => {
                return (
                  <RollbarContext context={path}>
                    <LazyRoute ... />
                  </RollbarContext>
                );
              })}
              <Redirect from="*" to="/app/404" />
            </Switch>
          </Route>
        </Router>
      </ErrorBoundary>
    </Provider>

I'm using the following versions of the libraries:

  • rollbar@2.26.2
  • @rollbar/react@0.11.2

Activity

  1. jerimiahmilton commented on Jul 11, 2024

    @jerimiahmilton

    Running into the same issue, here's my usage:

    const Chat: React.FC = () => {
      useRollbarContext('chat#list')
    
      return (
        <IonPage>
          <Header title='Chat' />
          <IonContent>
            <CometChatConversationsWithMessages
              isMobileView={true}
              messagesConfiguration={messageConfig}
              conversationsConfiguration={conversationConfig}
            />
          </IonContent>
        </IonPage>
      )
    }
    
    export default Chat
    
  2. mxwoz1234 commented on Oct 17, 2024

    @mxwoz1234

    I have a similar issue.

    `
    const rollbarConfig = {
    accessToken: 'xxxxx',
    environment: 'production',
    };
    export default function App() {
    return (

                <Router>
                    <div>
                      
                           <Provider config={rollbarConfig}>
                               <ErrorBoundary
                                   fallbackUI={ErrorBoundaryMessage}
                               >
                                    <Suspense fallback={<LoadingAdvice/>}>
                                        <Switch>
                                            <Route path="/register/start/:guid">
                                               <RollbarContext context={'registerStart'} >
                                                    <RegisterStart />
                                                </RollbarContext>
                                            </Route>
                                            
    
                                        </Switch>
                                    </Suspense>
                               </ErrorBoundary>
                           </Provider>
                    </div>
                </Router>
            </ThemeProvider>
        </StyledEngineProvider>
    );
    

    }
    `

  3. DToppingWW commented on Feb 18, 2025

    @DToppingWW

    I came across this same issue as well, using: @rollbar/react: 0.11.2, rollbar: 2.26.4

    I think the Rollbar library should be able to set a default payload if none is provided in the initial config.

    Workaround:

    Setup the Provider to have a default value in the config for payload.

    import { Provider } from '@rollbar/react';
    
    // ...
    
    <Provider
      config={{
        enabled: true,
        payload: {},
      }}
    >

    as long as the payload object is defined initially, then setting a context later will not throw an error.

  4. added a commit that references this issue on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions