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.

TypeError: Cannot read property 'subscriptions' of undefined

See original GitHub issue

Am receiving this error in my test of a component that uses RTKQ to fetch data and I cannot figure out where it’s coming from and how to get around/fix it.

My API looks like so:

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';

interface PanelContentInterface { 
  header?: any;
  body?: any;
}

interface PanelRequestPayload {
  endpoint: string;
  caseID: string;
}

export const panelApi = createApi({
  reducerPath: 'panel',
  baseQuery: fetchBaseQuery({
    baseUrl: 'https://jsonplaceholder.typicode.com/'),
  }),
  endpoints: builder => ({
    panelData: builder.query<PanelContentInterface, PanelRequestPayload>({
      query: ({ endpoint, id }) => `${endpoint}/${id}`,
      transformResponse: (response: any) => response.data,
    }),
  }),
});

export const { usePanelDataQuery } = panelApi;

The test for the panel component is rather straight forward (redundant) but still fails.

test('should render correctly', () => {
    render(<Panel endpoint="test-enpoint" testID="test-panel" />);
    expect(screen.getByTestId('test-panel')).toBeInTheDocument();
});

I receive both Error: No data found at 'state.panel'. Did you forget to add the reducer to the store? and Error: Uncaught [TypeError: Cannot read property 'subscriptions' of undefined]

Can anyone help?

I’m using this very same method in multiple other places in the same project and they all seem to work fine.

Additional Context:

const { data, isSuccess, isLoading } = usePanelDataQuery(payload);

This line pops up in the console too, but the issue I’m having is that this error only appears in the test and not in the component. The component receives the data and will render properly.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
phryneascommented, May 19, 2022

Please send your lead our way. They are crippling your app going forward, for no good reason.

0reactions
phryneascommented, May 19, 2022

For separate files you don’t need multiple apis. That is documented in the chapter Code Splitting.

If you ever want to have something like automatic refetching of endpoints with invalidatesTags/providesTags, those have to be in the same api.

Multiple apis make sense if you talk to completely independent data sources that will never have an overlap - say an api for cookie recipes and an api about dog breeds. If they ever interact or reference each other (say, a comment on a post with an author), those are the same api.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: Cannot read property 'subscription' of undefined
I am using a JS script to implement the Stripe payment provider on a website. The code mainly comes from this tutorial from...
Read more >
Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError: Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Cannot read property 'subscribe' of undefined - ng-mocks
This issue means that something has been replaced with a mock object and returns a dummy result ( undefined ) instead of observable...
Read more >
Cannot read property comment of undefined on some schema ...
i have some problem in some query data returning null or undefined from schema[typedefs] after adding comment, this data returning null or ...
Read more >
[SOLVED] Cannot Read Property of Undefined in JavaScript
The “cannot read property of undefined” error occurs when you attempt to access a property or method of a variable that is undefined...
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