Redux: Uncaught TypeError: Cannot read properties of undefined (reading 'mySlice')

Nick Raphael - Jun 21 '22 - - Dev Community

Oh man, I just had a really annoying redux-toolkit error...

Uncaught TypeError: Cannot read properties of undefined (reading 'mySlice')
Enter fullscreen mode Exit fullscreen mode

This was caused by a circular dependency in my file structure. I have a file structure like this...

stuff
  -> store
    -> index.ts
       reducer.ts
       selectors.ts
  feature
    -> store
      -> index.ts
         slice.ts
         selectors.ts
Enter fullscreen mode Exit fullscreen mode

Any code outside of the store files references store stuff via the index.tx which just exports all the other files.

My problem was a selector referencing a selector from a higher level in my store structure via another index.ts. The reducer at this higher level was referencing the slice at the lower level, again via index.ts.
This is a circular reference. To fix it, I chose to remove the higher level index.ts and reference the selector file directly.

Hope this helps somebody.

. . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player