Cory Robinson
Cory Robinson

Reputation: 5272

Array.prototype.includes - not transformed with babel

I cannot figure out how to get this code to transform to compatible code in Node.js v4 env: [].includes('anything')

Becuase this throws an error in Node.js v4 Error: includes is not a function...

Can anyone help me understand why babel does not transform .includes()? I have tried using babel-preset-es2015 and babel-preset-es2016 as well as the babel repl: Example babel repl code usage

Upvotes: 3

Views: 3047

Answers (1)

haichao
haichao

Reputation: 11

You need to import babel-polyfill to use static methods like Array.from or Object.assign, instance methods like Array.prototype.includes.

If you don't want to modify globals, checkout the transform-runtime plugin. This means you won't be able to use the instance methods mentioned above like Array.prototype.includes.

Upvotes: 1

Related Questions