-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Closed
Labels
needs triageThis issue needs to be triaged by the teamThis issue needs to be triaged by the team
Description
Description
<mat-icon svgIcon="..." /> throw error on npm run prerender.
Previous reports of this issue:
- Error retrieving icon universal#2685
(closed claiming insufficient information) - Universal and Angular Material Icon ERROR Error: Error retrieving icon :lock! ErrorEvent is not defined universal#2573
(closed claiming insufficient information) - Error when retrieving icon from registry in server side rendering #9728
(reported in Feb 2018 and closed by the author after getting no solution for ~4 years, and locked by the amazing bot.)
Reproduction
Steps to reproduce:
- Create new project:
ng new test-prerender-svg-icon - Add Angular Material:
ng add @angular/material - Add Angular Universal:
ng add @nguniversal/express-engine - Download any svg icon like https://angular.io/assets/images/logos/angular/angular.svg into
src/assets/ - app.component.html: Replace all default content with:
<mat-icon svgIcon="angular" />
- app.module.ts:
import { HttpClientModule } from '@angular/common/http'; import { NgModule } from '@angular/core'; import { MatIconModule, MatIconRegistry } from '@angular/material/icon'; import { BrowserModule, DomSanitizer } from '@angular/platform-browser'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { AppComponent } from './app.component'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule.withServerTransition({ appId: 'serverApp' }), BrowserAnimationsModule, HttpClientModule, // Required for using iconRegistry. MatIconModule, ], providers: [], bootstrap: [AppComponent] }) export class AppModule { constructor(iconRegistry: MatIconRegistry, sanitizer: DomSanitizer) { // See: https://material.angular.io/components/icon/overview#svg-icons. iconRegistry.addSvgIcon('angular', sanitizer.bypassSecurityTrustResourceUrl('/assets/angular.svg')); } }
ng serveworks fine and shows the svg icon.npm run prerender=>ERROR Error: Error retrieving icon :angular!- Same error with
npm run dev:ssr.
Expected Behavior
Expected <mat-icon svgIcon="angular" /> to work with Angular Universal prerendering (just like it works fine with ng serve).
Actual Behavior
npm run prerender throws Error retrieving icon:
⠹ Prerendering 1 route(s) to ~/test-prerender-svg-icon/dist/test-prerender-svg-icon/browser...ERROR Error: Error retrieving icon :angular!
at Object.error (~/test-prerender-svg-icon/dist/test-prerender-svg-icon/server/main.js:1:3655776)
at ConsumerObserver2.error (~/test-prerender-svg-icon/dist/test-prerender-svg-icon/server/main.js:1:1216955)
at SafeSubscriber2.Subscriber2._error (~/test-prerender-svg-icon/dist/test-prerender-svg-icon/server/main.js:1:1216140)
at SafeSubscriber2.Subscriber2.error (~/test-prerender-svg-icon/dist/test-prerender-svg-icon/server/main.js:1:1215674)
at OperatorSubscriber2.Subscriber2._error (~/test-prerender-svg-icon/dist/test-prerender-svg-icon/server/main.js:1:1216140)
at OperatorSubscriber2.Subscriber2.error (~/test-prerender-svg-icon/dist/test-prerender-svg-icon/server/main.js:1:1215674)
at OperatorSubscriber2.Subscriber2._error (~/test-prerender-svg-icon/dist/test-prerender-svg-icon/server/main.js:1:1216140)
at OperatorSubscriber2.Subscriber2.error (~/test-prerender-svg-icon/dist/test-prerender-svg-icon/server/main.js:1:1215674)
at OperatorSubscriber2.Subscriber2._error (~/test-prerender-svg-icon/dist/test-prerender-svg-icon/server/main.js:1:1216140)
at OperatorSubscriber2.Subscriber2.error (~/test-prerender-svg-icon/dist/test-prerender-svg-icon/server/main.js:1✔
Prerendering routes to ~/test-prerender-svg-icon/dist/test-prerender-svg-icon/browser complete.Environment
- @angular/cli:
15.1.6 - @angular/core:
15.1.6 - @angular/material:
15.1.5 - @nguniversal/express-engine
15.1.0
cc: @alan-agius4
Metadata
Metadata
Assignees
Labels
needs triageThis issue needs to be triaged by the teamThis issue needs to be triaged by the team