Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular elements error . "Failed to construct 'HTMLElement ...'

I am trying out a very simple application on angular elements on stackblitz and I am getting the following issue.

Error: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.

All I am trying to do is trying to display hello world. I didn't face any issue doing this on visual code locally, however, this issue comes up on stackblitz. Not sure I have to follow some additional steps on stackblitz in order for me to run this application. Appreciate any help on this.

Here is the link to the application on stackblitz.

like image 321
Malik Avatar asked May 27 '18 15:05

Malik


3 Answers

Downgrade document-register-element to v1.8.1 solved it.

npm i [email protected]

Work for me.

Cr. https://github.com/angular/angular/issues/24390#issuecomment-396729418

like image 87
bamossza Avatar answered Oct 18 '22 21:10

bamossza


If anyone's facing the issue, and wants to still target ES5 (for IE compatibility or other reasons), another reasonable solution is to use the web component ES5 adapter polyfills.

# Install the package
npm install @webcomponents/webcomponentsjs --save-dev

# Then add the following line in Polyfills.ts
import '@webcomponents/webcomponentsjs/custom-elements-es5-adapter.js'; 

From this GitHub issue.

like image 31
Arghya C Avatar answered Oct 18 '22 21:10

Arghya C


For anyone having this issue, just change the target to es6 or es2015 in your tsconfig.json file. That will work perfectly.

like image 1
Suraj Khanal Avatar answered Oct 18 '22 20:10

Suraj Khanal