DEV Community

websplee
websplee

Posted on

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

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.

Top comments (3)

Collapse
 
gmcfarlane profile image
gmcfarlane

hey there, i think this may be the post i am looking for... i put the imports in the other module. do i also need to do the declares? exports?

sorry... still struggling w/ what makes angular easy.... XD

Collapse
 
rohanayush profile image
rohanayush

Hi, could you please give example from code , as I am having the same issue. Kindly reply to this. Thanks

Collapse
 
moshmage profile image
moshmage

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