Angular - ERROR in 'router-outlet' is not a known element:

websplee profile image websplee ・1 min read

I have been supporting this massive Angular app and from the time I took over support, I was told "ng build --prod" never works. Of course, we did a couple of things that I am not proud of to go round this issue.

So the detailed error when building for prod has been: -
ERROR in 'router-outlet' is not a known element: 1. If 'router-outlet' is an Angular component, then verify that it is part of this module. 2. If 'router-outlet' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. (" [ERROR ->] ")

A quick Google (I actually did a lot of searching) took me to these places, which have great material about this issue: -

  1. Stackoverflow - https://stackoverflow.com/questions/44517737/router-outlet-is-not-a-known-element

None of that worked for me :(.

I then started working my way through all the app modules and discovered that there were a couple of modules which did not have routing defined. Voila. I added routing to all of these modules and this app is now successfully compiling with the --prod flag.

Posted on by:

websplee profile



I have been managing IT for financial institutions for over 12 years. I am now doing what I love, writing code!!!


Editor guide

This post shaved a shitload of time hunting for fairies. Thank you kindly.