2017-02-27 174 views
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”。我试过改变垫片的顺序,排除原生垫片。

回答

1

根据错误信息,这是因为没有标签名称。

你应该定义一个有,例如:

customElements.define('todo-app', TodoApp)