Error extending HyperHTMLElement

122 Views Asked by At

I'm trying to define a trivial custom element using HyperHTMLElement, however I can't seem to extend HyperHTMLElement without getting complaints from Chrome (as well as Safari).

src/index.js

import 'document-register-element'
import HyperHTMLElement from 'hyperhtml-element/esm'

const { bind } = HyperHTMLElement

class Hello extends HyperHTMLElement {
  created() { this.textContent = 'hello' }
}
Hello.define('hello-element')

bind(document.body)`<hello-element />`

rollup.config.js

import nodeResolve from 'rollup-plugin-node-resolve'
import commonjs from 'rollup-plugin-commonjs'
import babel from 'rollup-plugin-babel'

export default {
  input: 'src/index.js',
  output: [{ file: 'bundle.js', sourcemap: 'inline', format: 'iife', name: 'oye' }],
  plugins: [
    babel({
      exclude: 'node_modules/**',
      presets: [ ["env", { "modules": false }] ],
      plugins: [ "external-helpers" ]
    }),
    nodeResolve({ module: true, jsnext: true, main: true, browser: true }),
    commonjs(),
  ]
}

index.html:

<!DOCTYPE html>
<html>
  <head></head>
  <body>
    <script type="text/javascript" src="bundle.js"></script>
  </body>
</html>

Rollup bundles everything without errors:

enter image description here

However, Chrome reports this:

enter image description here

I've also tried switching to Webpack+Babel, to no avail — the same stack trace is still reported (with Webpack specific minor differences).

1

There are 1 best solutions below

1
Erik Kaplun On

Looks like babel needs to be told no to exclude node_modules/hyperhtml-element/**:

export default {
  ...
  plugins: [
    babel({
      exclude: 'node_modules/**',
      include: 'node_modules/hyperhtml-element/**',
      presets: [ ["env", { "modules": false }], 'stage-3' ],
      plugins: [
        // ["transform-es2015-classes", { "loose": true }],
        "external-helpers"
      ]
    }),
    ...
  ],
  ...
}

However, I'm not entirely sure this is the right solution.