1
我在尝试使用webpack执行简单的自定义元素时出现此错误。TypeError:fakeClass不是构造函数
我的设置:
<script src="/custom-elements.min.js"></script>
<script src="/native-shim.js"></script>
export default class TodoApp extends HTMLElement {
constructor() {
super();
console.log('CONSTRUCT');
}
}
在本机垫片的第98行发生错误:
window.HTMLElement = function() {
if (!browserConstruction) {
const tagname = tagnameByConstructor.get(this.constructor);
const fakeClass = nativeGet.call(window.customElements, tagname);
// Make sure that the fake constructor doesn't call back to this constructor
userConstruction = true;
const instance = new (fakeClass)();
return instance;
}
// Else do nothing. This will be reached by ES5-style classes doing
// HTMLElement.call() during initialization
browserConstruction = false;
};
“变量名” 是不确定的。
我试过不同版本的babel,包括“latest”。我试过改变垫片的顺序,排除原生垫片。