simpl-schema: TypeError: Array.includes is not a function @0.0.4

I got this error message in both client (Chrome v.57) & server code.

I20161228-11:17:22.178(7)? Exception in setInterval callback: TypeError: Array.includes is not a function
I20161228-11:17:22.180(7)?     at Object.runAV (node_modules\simpl-schema\dist\clean\setAutoValues.js:51:15)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 12
  • Comments: 17 (1 by maintainers)

Most upvoted comments

Personally, I prefer @eluck 's last snippet. It’s small, and essentially the only thing required. Adding the entire babel-polyfill seems overkill.

Preferably, this should be refactored in this source, though.

Created a PR (#42) to fix this issue. Given the project already requires underscore, I opted for using _.contains.

Update:

If everywhere in the app I change the import:

import SimpleSchema from 'simpl-schema';

to

import 'babel-polyfill';
import SimpleSchema from 'simpl-schema';

the error message TypeError: Array.includes is not a function disappears.

@seabrus I can confirm that install babel-polyfill with npm install babel-polyfill --save-dev and import it to my page as import 'babel-polyfill'; can fix this issue.

@aldeed can you suggest better way to fix this?

@dburles Pretty sure that was fixed when this got merged. I’ve removed babel-polyfill from my project and haven’t seen any issues.

@saeedjalali1 because babel-polyfill was removed and the code still make use of Array.includes (not Array.prototype.includes), which is defined by babel-polyfill. It seems that this test case was not covered. Added a stub for Array.includes or including babel-polyfill back into your project resolves this as both declare the required, missing, implementation.

The proper solution, however, is for this repository to properly call an alternative implementation and not use Array.includes at all. Because babel-polyfill is completely useless in this case.