Immer: Undefined is not a function

Created on 16 Sep 2019  Â·  12Comments  Â·  Source: immerjs/immer

I realize this is not enough information at all but I hope you can help me find the problem if possible.

Our Bugsnag is reporting the following error:

TypeError undefined is not a function 
    ../node_modules/immer/dist/immer.module.js:121 each
    ../node_modules/immer/dist/immer.module.js:503 Object.<anonymous>
    ../node_modules/immer/dist/immer.module.js:1113:15 Object.<anonymous>
    https://dwf.hockeyweerelt.nl/:1:1651 f
    api/comments.js:29:55 Object.push.615
    https://dwf.hockeyweerelt.nl/:1:1651 f
    https://dwf.hockeyweerelt.nl/static/js/main.7417baf1.chunk.js:1:84 Object.push.279
    https://dwf.hockeyweerelt.nl/:1:1651 f
    https://dwf.hockeyweerelt.nl/:1:1520 p
    https://dwf.hockeyweerelt.nl/:1:1383 Array.e [as push]

From what I can tell the problem comes from the following piece of code:

function each(value, cb) {
  if (Array.isArray(value)) {
    for (var i = 0; i < value.length; i++) {
      cb(i, value[i], value);
    }
  } else {
    ownKeys(value).forEach(function (key) {
      return cb(key, value[key], value);
    });
  }
}

Specifically ownKeys -- This is an assumption but I think ownKeys is somehow undefined. I came to this assumption because that's what's on line 121.

The affected browsers are:

  1. Edge 16.16299.0
  2. Edge 18.17763.0
  3. Edge 17.17134.0
  4. Chrome 60.0.3112
  5. Chrome 61.0.3163
  6. Chrome 72.0.3626
  7. Chrome 73.0.3683
  8. Chrome 74.0.3729
  9. Chrome 75.0.3770
  10. Chrome 76.0.3809

Reproduction

I honestly don't know, I've tried reproducing it but unfortunately

It works on my machine

I also can't reproduce it on BrowserStack.

Environment

  • Immer version: 1.7.2
  • [x ] Occurs with setUseProxies(true) -- Assuming this is the default
  • [ ] Occurs with setUseProxies(false) (ES5 only)
cannot reproduce

Most helpful comment

Hi @mweststrate

I have this issue in react-native with immer v7 and hermes enabled (the issue only happens with hermes enabled).

Steps to reproduce:

  • Clone this repo
  • Run project (yarn android or yarn ios)
  • In the welcome screen touch the number

Immer v6 works with hermes.
You can change to immer v6 in these lines:

All 12 comments

It might be a problem with another dependency, build setup thing you have,
like a misconfigured polyfill. Im afraid we can't do much without isolated
test case.

Op ma 16 sep. 2019 12:27 schreef jordyvandomselaar <[email protected]

:

I realize this is not enough information at all but I hope you can help me
find the problem if possible.

Our Bugsnag is reporting the following error:

TypeError undefined is not a function
../node_modules/immer/dist/immer.module.js:121 each
../node_modules/immer/dist/immer.module.js:503 Object.
../node_modules/immer/dist/immer.module.js:1113:15 Object.
https://dwf.hockeyweerelt.nl/:1:1651 f
api/comments.js:29:55 Object.push.615
https://dwf.hockeyweerelt.nl/:1:1651 f
https://dwf.hockeyweerelt.nl/static/js/main.7417baf1.chunk.js:1:84 Object.push.279
https://dwf.hockeyweerelt.nl/:1:1651 f
https://dwf.hockeyweerelt.nl/:1:1520 p
https://dwf.hockeyweerelt.nl/:1:1383 Array.e [as push]

From what I can tell the problem comes from the following piece of code:

function each(value, cb) {
if (Array.isArray(value)) {
for (var i = 0; i < value.length; i++) {
cb(i, value[i], value);
}
} else {
ownKeys(value).forEach(function (key) {
return cb(key, value[key], value);
});
}
}

Specifically ownKeys -- This is an assumption but I think ownKeys is
somehow undefined.

The affected browsers are:

  1. Edge 16.16299.0
  2. Edge 18.17763.0
  3. Edge 17.17134.0
  4. Chrome 60.0.3112
  5. Chrome 61.0.3163
  6. Chrome 72.0.3626
  7. Chrome 73.0.3683
  8. Chrome 74.0.3729
  9. Chrome 75.0.3770
  10. Chrome 76.0.3809

Reproduction

I honestly don't know, I've tried reproducing it but unfortunately

It works on my machine

I also can't reproduce it on BrowserStack.
Environment

  • Immer version: 1.7.2
  • [x ] Occurs with setUseProxies(true) -- Assuming this is the default
  • Occurs with setUseProxies(false) (ES5 only)

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/immerjs/immer/issues/425?email_source=notifications&email_token=AAN4NBGQHO64NFFPVQVRIBTQJ5UTJA5CNFSM4IXA6OVKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HLRXA2Q,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAN4NBAGLXGH7QLYJOZPDG3QJ5UTJANCNFSM4IXA6OVA
.

Alright, thanks for having a look! I'll close this issue for now and re-open it if at some point I find more useful information.

Just to add another (rather useless) datapoint, I have been getting this runtime issue as well in Rollbar with Immer 5.0.1.
The issue has appeared in a range of browsers Chrome 60 and 78 and is due to ownKeys not being defined. Also cant not reproduce.

Also adding a (semi useless) datapoint in that we are seeing this often, with immer 6.0.1. We also use rollbar, seeing this a few hundred times a day, all on Windows 8/10, recent chrome (79, 80 at this time). Also no luck reproducing in browserstack. Seeing this come up across a few thousand different IPs, so it's not just a few odd users. I traced through our minified code to arrive at the some conclusion at the OP, in that ownKeys is somehow undefined.

Since I can't reproduce, or provide an isolated case, I know this is not super useful, but figured it was worth adding data points in case someone can build up a better picture.

I pushed a possible fix as 6.0.0-fix-425-2. I think that should theoretically not happen, but feel free to roll it out at own risk and check if that removes the errors.

@mweststrate thanks for the patch fix. We pushed that out to production last week, and unfortunately, we're seeing the same rate of errors coming in. The only new information I have is that we've recently started seeing some errors from Edge 18 in addition to Chrome, but still all on Windows.

Also seeing this. Similarly all on Chrome/Windows users. Happens when redux-toolkit > immer calls ownKeys(value).forEach(...)

Would be great if people here share what webpack / babel / polyfill setups they are using. I highly suspect that there is a broken polyfill somewhere, that causes one of the built-ins used by ownKeys to be undefined, since the fallback getOwnPropertyNames should be supported by all browsers.

It would be great if someone could check if Immer 7 somehow magically fixes this :). Not that I did anything deliberately to address is, but some built-ins have been swapped with different functionality, and Immer can now handle polyfilled symbols better.

Hi @mweststrate

I have this issue in react-native with immer v7 and hermes enabled (the issue only happens with hermes enabled).

Steps to reproduce:

  • Clone this repo
  • Run project (yarn android or yarn ios)
  • In the welcome screen touch the number

Immer v6 works with hermes.
You can change to immer v6 in these lines:

Hi @mweststrate

I have this issue in react-native with immer v7 and hermes enabled (the issue only happens with hermes enabled).

Steps to reproduce:

  • Clone this repo
  • Run project (yarn android or yarn ios)
  • In the welcome screen touch the number

Immer v6 works with hermes.
You can change to immer v6 in these lines:

Same here, I'm having the same issue when using v7 with Hermes enabled. Any idea on how to fix it using V7?

@ahce / @elkinjosetm could you please open a new issue, as this one is closed and about IE and Chrome, not hermes? Comments on closed issues are typically not seen by others.

If you could infer from the stack or a debugger break point which function is undefined that'd be great.

Was this page helpful?
0 / 5 - 0 ratings