2017-02-27 177 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)