I have an Angular v21 app that I've configured to use SSR, and it is failing on certain prerendered routes while trying to build, with unclear errors. I've looked around and tried different combinations of isPlatformBrowser and afterNextRender/afterEveryRender, wrapping window and document usages in afterNextRender/afterEveryRender, as well as removing the Firebase, fetch, or meta editing code that could potentially conflict, with no change to the error.
One of the errors:
[ERROR] An error occurred while prerendering route '/music/releases'.
Error: Terminating worker thread
at Object.ThreadTermination (.../node_modules/piscina/dist/errors.js:5:30)
at WorkerInfo.destroy (.../node_modules/piscina/dist/worker_pool/index.js:81:43)
at ThreadPool._removeWorker (.../node_modules/piscina/dist/index.js:259:20)
at ThreadPool.destroy (.../node_modules/piscina/dist/index.js:474:18)
at WorkerPool.destroy (.../node_modules/piscina/dist/index.js:645:65)
at .../node_modules/@angular/build/src/utils/server-rendering/prerender.js:166:35
at async Promise.all (index 4)
at async renderPages (.../node_modules/@angular/build/src/utils/server-rendering/prerender.js:170:9)
at async prerenderPages (.../node_modules/@angular/build/src/utils/server-rendering/prerender.js:107:49)
at async executePostBundleSteps (.../node_modules/@angular/build/src/builders/application/execute-post-bundle.js:70:73)
Music-Releases.Component.ts
@Component({
selector: 'app-music-releases',
imports: [KeyValuePipe, MusicComponent, SvgComponent],
templateUrl: './music-releases.component.html',
styleUrl: './music-releases.component.scss',
})
export class MusicReleasesComponent {
private firebase = inject(FirebaseService);
private meta = inject(Meta);
ngOnInit(){
this.meta.updateTag({content: meta_tags.music_releases.description, name:'twitter:description'});
this.meta.updateTag({content: meta_tags.music_releases.description, name:'description'});
this.meta.updateTag({content: meta_tags.music_releases.image, name:'twitter:image'});
this.meta.updateTag({content: meta_tags.music_releases.image, name:'og:image'});
this.meta.updateTag({content: meta_tags.music_releases.title, name:'twitter:title'});
}
artists = this.firebase.getArtists();
bundle = (str: string) => bundle(str, "/images/music/");
link = link;
keys = Object.keys;
sort = sortLink;
}
Music.Component.ts
@Component({
selector: 'app-music',
imports: [RouterLink, RouterLinkActive],
templateUrl: './music.component.html',
styleUrl: './music.component.scss'
})
export class MusicComponent {
private router = inject(Router);
private firebase = inject(FirebaseService);
artists = this.firebase.getArtists();
scrolled = false;
constructor() {
afterNextRender(() => {
window.onscroll = ev => {
this.scrolled = window.scrollY > 20;
}
})
}
link = link;
active = (path = "/", exact = true) => active(this.router, path, exact);
}
The firebase service has calls to firestore wrapped in an Angular signal resource. The file is much longer but I can share it if needed.