New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Failed to construct 'HTMLElement': Please use the 'new' operator #5
Comments
Does this happen in the example app or in your own? This error means, that you need a polyfill for browser that do support (!) Custom Elements. That sounds a bit strange, but Custom Elements are defined for EcmaScript 2015+ (bases upon classes) and for supporting older browser, we normally compile down to EcmaScript 5 today. Normally, I'm loading this polyfill:
And then, I'm referencing it in the angular.json:
To support browsers that DO NOT know Custom Elements, I'm also referencing another polyfill of this package in the polyfills.ts:
|
Following your instructions i'm still having the same error. |
@DanielNetzer i had the same issue, it depends on the order you import the scripts. <!-- not working -->
<script src="main.js" defer></script>
<script src="scripts.js" defer></script> When you first import <script src="scripts.js" defer></script>
<script src="main.js" defer></script> (freaking proxy doesn't allow me to upload a Screenshot, i will deliver that later ) |
Following on the previous comment: The order of the scripts in angular.json matters! The polyfills need to come before If you install the schematics out of order, it will place the scripts out of order. |
How come I have to use polyfill-webcomp-es5 with Chrome 89? I tried using without polyfill-webcomp-es5 as well as trying without polyfill-webcomp. Both of these produce the error: ': Please use the 'new' operator, this DOM object constructor cannot be called as a function. Only way I could it to work is to use the polyfill-webcomp-es5 shim.
|
Same here, need to use I wonder why with ngx-build-plus it does not work, but without ngx-build-plus it works without any polyfill. A polyfill is only needed for older browsers that do NOT support web components, as described in the Angular docs: Any ideas? |
I figured out that when using |
the example works, but when I try to apply that to my component, it keeps throwing these errors on
customElements.define('custom-element', customElement);
Uncaught TypeError: Failed to construct 'HTMLElement': Please use the 'new' operator, this DOM object constructor cannot be called as a function.
at NgElementImpl.NgElement [as constructor] (elements.js:391)
at new NgElementImpl (elements.js:427)
at new AppModule (app.module.ts:42)
at createClass (core.js:8213)
at createProviderInstance$1 (core.js:8185)
at initNgModule (core.js:8118)
at new NgModuleRef (core.js:8844)
at createNgModuleRef (core.js:8833)
at Object.debugCreateNgModuleRef [as createNgModuleRef] (core.js:10658)
at NgModuleFactory.push.../../node_modules/@angular/core/fesm5/core.js.NgModuleFactory_.create (core.js:11360)
The text was updated successfully, but these errors were encountered: