Angular Universal: HTMLElement is not defined
See original GitHub issue🐞 bug report
Affected Package
The issue is caused by package @angular/elementsDescription
Using Angular Elements (specifically createCustomElement
) breaks SSR.
🔬 Minimal Reproduction
Here’s a repository that reproduces the issue: https://github.com/juristr/repro-angular-elements-with-ssr-issue
It’s a newly generated Angular CLI app + with SSR using @nguniversal/hapi-engine
.
This commit works 96f5ed9fc5f40ab61be09854200ff404090698e1, but once I add @angular/elements
it breaks.
🔥 Exception or Error
/Users/.../ngssr/dist/ngssr/server/main.js:55010
class NgElement extends HTMLElement {
^
ReferenceError: HTMLElement is not defined
at Module.Dti6 (/Users/.../ngssr/dist/ngssr/server/main.js:55010:25)
at __webpack_require__ (/Users/.../ngssr/dist/ngssr/server/main.js:20:30)
at Module.ZAI4 (/Users/.../ngssr/dist/ngssr/server/main.js:78554:75)
at __webpack_require__ (/Users/.../ngssr/dist/ngssr/server/main.js:20:30)
at Module.24aS (/Users/.../ngssr/dist/ngssr/server/main.js:38572:69)
at __webpack_require__ (/Users/.../ngssr/dist/ngssr/server/main.js:20:30)
at Module.K011 (/Users/.../ngssr/dist/ngssr/server/main.js:61050:80)
at __webpack_require__ (/Users/.../ngssr/dist/ngssr/server/main.js:20:30)
at Module.uj+Y (/Users/.../ngssr/dist/ngssr/server/main.js:155539:74)
at __webpack_require__ (/Users/.../ngssr/dist/ngssr/server/main.js:20:30)
A server error has occurred.
🌍 Your Environment
Angular Version:
Angular CLI: 11.0.2
Node: 12.14.0
OS: darwin x64
Angular: 11.0.2
... animations, cli, common, compiler, compiler-cli, core
... elements, forms, platform-browser, platform-browser-dynamic
... platform-server, router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1100.2
@angular-devkit/build-angular 0.1100.2
@angular-devkit/core 11.0.2
@angular-devkit/schematics 11.0.2
@nguniversal/builders 11.0.0
@nguniversal/hapi-engine 11.0.0
@schematics/angular 11.0.2
@schematics/update 0.1100.2
rxjs 6.6.3
typescript 4.0.5
Anything else relevant?
Related:
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Angular Universal SSR Issue - Element is not defined
I'm building a project in Angular using SAP Spartacus storefront. I need to enable SSR on this project, but when the server is...
Read more >angular/universal - Gitter
When I test it on the local server, it works normally. If I test it after deploying to firebase, an error occurs. I...
Read more >HTMLElement is not defined in TypeScript-angular.js
I understand you have 2 components that need to communicate. Specifically the "listener" needs to tell the "other component" that typing is finished....
Read more >AngularJS to Angular concepts: Quick reference
ng-hide In AngularJS, the ng-hide directive shows or hides the associated HTML element based on an expression. For more information, see ng-show. Bind...
Read more >Server-side Rendering (SSR) with Angular Universal
Check whether you have the latest Angular CLI which is 9 or greater. ng --version. If your CLI version is not as required,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@gkalpak, I think this can be closed now.
A little update:
Since #39994 is a breaking change, we are investigating other (non-breaking) solutions, such as assigning
domino.impl
ontoglobal
sooner. For reference, this assignment currently happens in the setDomTypes() function, which is called in aPLATFORM_INITIALIZER
.In the meantime, a simple work-around is to manually load
domino
sooner:Create a
src/app/load-domino.server.ts
file with the following content:At the top of
src/main.server.ts
(before theapp/server.module.ts
import) add an import to the previous file:UPDATE (2021-01-07): Changed suggestion to recommend importing in
main.server.ts
instead ofapp.server.module.ts
.