Compile ES6 HTMLElement class extensions to ES5
Switch branches/tags
Nothing to show
Clone or download
Latest commit f5067aa Jan 18, 2017


Compile Custom Element classes that extend HTMLElement for ES5 environments.


Custom Elements were designed for native ES6 classes that can extend host objects in ways prototypical inheritance can not. Using the Babel transform-es2015-classes transform will not work as is. You'll likely see a runtime error like "Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function." when attempting to extend HTMLElement in a Babel transpiled class.


A workaround is to use Reflect.construct to build a new HTMLElement instance expected by the constructor. This transform wraps any ES6 classes extending HTMLElement with an intermediary class that shims this behavior.


Chrome Firefox IE Opera Safari
Latest 10.1+ TP

With Custom Elements V1 polyfill

Chrome Firefox IE Opera Safari
Latest Latest 11 Latest 9.1+


$ npm install babel-plugin-transform-custom-element-classes


Via .babelrc


// include before transform-es2015-classes
  "plugins": [