最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I get Web Components to compile with TypeScript for IE11EdgeChromeFirefox? - Stack Overflow

programmeradmin1浏览0评论

Having set up a web project to use TypeScript/WebPack I cannot get Google Chrome to run the result:

The error reads: "Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function."

I learned that a shim is required for transpiling to ES5, but I still can't get this to work. That's probably because I don't want to add a <script> element to the HTML but instead I want to import "../node_modules/@webponents/webponentsjs/webponents-bundle"; in my .ts files.

How can I get this to work without adding <script> elements to my HTML files?

I took my tsconfig.json and webpack.config.js files from this tutorial.

Having set up a web project to use TypeScript/WebPack I cannot get Google Chrome to run the result:

The error reads: "Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function."

I learned that a shim is required for transpiling to ES5, but I still can't get this to work. That's probably because I don't want to add a <script> element to the HTML but instead I want to import "../node_modules/@webponents/webponentsjs/webponents-bundle"; in my .ts files.

How can I get this to work without adding <script> elements to my HTML files?

I took my tsconfig.json and webpack.config.js files from this tutorial.

Share Improve this question asked Feb 4, 2019 at 0:19 AxDAxD 3,1945 gold badges40 silver badges64 bronze badges 3
  • 1 Hopefully this helps – github./angular/angular/issues/24556 – Callam Commented Feb 4, 2019 at 0:38
  • It looks like this is making things work for Chrome, but IE11 fails with customElements is undefined. – AxD Commented Feb 4, 2019 at 17:30
  • 1 Found it, thanks to your hint. I'll add the solution here. – AxD Commented Feb 4, 2019 at 17:41
Add a ment  | 

1 Answer 1

Reset to default 6

Here's the solution:

npm install @webponents/webponentsjs --save-dev
import "@webponents/webponentsjs/webponents-bundle";
import '@webponents/webponentsjs/custom-elements-es5-adapter.js';

...

As far as I can see, this runs smoothly on Chrome, Firefox, Edge and IE11.

发布评论

评论列表(0)

  1. 暂无评论