redux-devtools-extension: When browser doesn't have the redux devtools extension the app throws an undefined error

My React/Redux app worked fine on my computer but when I sent it to someone else the app would fail to load altogether.

After some debugging it turns out that window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() was returning undefined, which meant that .apply() was being called on undefined, thereby causing the error.

I therefore propose to change this line in the documentation to:

window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__() : f => f

This will make sure that if the redux extension is not present, the store enhancer added will at least be a function, as opposed to undefined.

I will submit a pull request immediately.

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 34
  • Comments: 19 (5 by maintainers)

Commits related to this issue

Most upvoted comments

That’s because you’re including it inside the compose. In this case you should use window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose instead. See Advanced store setup.

i fixed mine, now my app can now run with or without reduxDevtool installed

i just changed

window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()

to

window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__() || compose

@Shadowman4205 I was having the same issue until I changed it slightly to match the Advanced Setup guide:

  const composeEnhancers =
    typeof window === 'object' &&
      (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
      (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose;

Here I’m passing an empty {} object to the __REDUX_DEVTOOLS_EXTENSION_COMPOSE__(). Only then it works, otherwise throws the same error you’re receiving. This feels counterintuitive to me.

I wonder why redux is not checking for undefined? Is assuming that all args are a function, but sometimes we want to pass undefined.

I needed to go from this:

const composeEnhancers = !__PROD__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : compose

To this:

const composeEnhancers = !__PROD__ ? (window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose) : compose