I'd like to create web components that should work on ie11. I'm compiling js with gulp (and gulp-babel, that includes babel 7).
By now, when I compile with Babel, it works in Chrome, but sends an error in ie11: Function.prototype.toString: 'this' is not a Function object
.
In gulpfile.js I have this:
.pipe(babel({
"presets": [
["@babel/preset-env", {
"targets": {
"browsers": [
"Chrome >= 52",
"FireFox >= 44",
"Safari >= 7",
"Explorer 11",
"last 4 Edge versions"
]
}
}]
]
}))
In js I have something like this (sample code I found on the web for testing):
class MyCustomTag extends HTMLElement {
connectedCallback() {
this.innerHTML = '<h2>My custom element</h2><button>click me</button>';
this.style.backgroundColor = 'blue';
this.style.padding = '20 px';
this.style.display = 'inline-block';
this.style.color = 'white';
}
}
try {
customElements.define('my-custom-tag', MyCustomTag)
} catch (err) {
const h3 = document.createElement('h3')
h3.innerHTML = "This site uses webcomponents which don't work in all browsers! Try this site in a browser that supports them!"
document.body.appendChild(h3)
}
Of course I added <my-custom-tag></my-custom-tag>
in HTML.
The error is thrown on something generated by Babel when "extends HTMLElement" is in the code (Babel generates something like "_.isNative" that uses Function.prototype.Tostring, if I remember well - sorry I'm currently on another computer) I'm sure I'm missing something stupid, but I can't find any answer on this error. I tried adding @babel/plugin-transform-classes, babel-plugin-transform-builtin-classes, but nothing works and it drives me crazy.
Any idea?