4663

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

Answer1:

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.

Recommend

  • I want to run unit test and espresso test cases a specific build type
  • what is good way to do merge the code in below scenarion (Git,Intellij,Stash)?
  • Can I generate a JSON file with javascript?
  • Babel + Mocha stack traces report wrong line number
  • How to pass ngModel to AngularJS component without 2-way binding?
  • How do I implement camera changing from front to back camera
  • Android Studio 3.0 Canary 1 - Simulator stuck on boot
  • Changing column based on header ComboBox selection
  • How to deploy react with express to heroku
  • Webpack: How to merge css and less, THEN apply cssnano
  • sass-loader not working with webpack + react + grommet
  • Why the prototype can be retrieved but the __proto__ is undefined in JavaScript?
  • How to easily inspect styled-components using dev tools?
  • Preset files are not allowed to export objects
  • “babelHelpers.asyncToGenerator is not a function” on React-Native 0.16.0 and 0.17.0
  • scope of the mouse adapter
  • How can I apply differnt styles when transforming data using json2html based on data value?
  • Implicit property animations do not work with CAReplicatorLayer?
  • Change the width of the JQM panels
  • What's a fast (non-loop) way to apply a dict to a ndarray (meaning use elements as keys and rep
  • Is it mandatory to have a doGet or doPost method?
  • Authentication failed with Azure Active Directory in Windows Phone
  • Creating Java object from class name with constructor, which contains parameters [duplicate]
  • MonoTouch: How to download pdf incrementally as indicated in the Apple slides “Building Newsstand Ap
  • Installing Apache MyFaces 2 on WildFly 8.2.0
  • How to use RequestBodyAdvice
  • Using jQuery closest() method with class selector
  • Build own AppleScript numerical error handling
  • Websockets service method fails during R startup
  • Google cloud sdk not working when python points python3
  • Is there a mandatory requirement to switch app.yaml?
  • Why can't I rebase on to an ancestor of source changesets if on a different branch?
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • Binding checkboxes to object values in AngularJs
  • Net Present Value in Excel for Grouped Recurring CF
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?