设置了一个Web项目以使用TypeScript/WebPack之后,我无法让Google Chrome运行结果:
该错误显示为:“未捕获的TypeError:无法构造'HTMLElement':请使用'new'运算符,此DOM对象构造函数不能作为函数调用。”
我了解到a shim is required可移植到ES5,但是我仍然无法使用它。那可能是因为我不想在HTML中添加元素,而是想在import "../node_modules/@webcomponents/webcomponentsjs/webcomponents-bundle";
文件中添加.ts
。
如何在不向HTML文件中添加元素的情况下使其工作?
我从this tutorial中获取了tsconfig.json
和webpack.config.js
文件。
最佳答案
解决方法如下:
npm install @webcomponents/webcomponentsjs --save-dev
import "@webcomponents/webcomponentsjs/webcomponents-bundle";
import '@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js';
...
据我所知,它可以在Chrome,Firefox,Edge和IE11上顺利运行。
关于javascript - 如何获得Web组件以用于IE11/Edge/Chrome/Firefox的TypeScript进行编译?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54508917/