0

What I have done so far (and what worked fine)

I have an angular-app that is used by multiple different customers, which I am currently updating from angular 4 to angular 6. The customers have their own differing extensions so in angular 4 I created one module for each customer (which sets up the customizations) and then I created one environment.CUSTOMER_NAME.ts file for each customer with a content like this:

export const environment: Environment = {
    extraModules: [MODULE_FOR_THIS_CUSTOMER]
};

Then in my main module I used:

@NgModule({
    imports: (<Array<Type<any> | ModuleWithProviders | any[]>>[
        BrowserModule,
        FormsModule,
        /* .. */
    ].concat(environment.extraModules)),
    /* .. */
})
export class AppModule { }

That worked great. Running ng build --env=SOME_CUSTOMER build the whole application including the modules for that particular customer.

The problem

Now I upgraded to angular 6 and I was getting the error:

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 ->]<router-outlet></router-outlet>")

After a day of building up grey hair and considering to quit my job and become a bus driver, I eventually figured out, that my concat-command seems to be the root of the problem. At least it is in combination with the options

"aot": true,
"buildOptimizer": true,

in the angular.json file. If I set both of those to false, everything works fine, even with my old structure. Removing the concat command also fixes the problem.

Naturally I don't really want to leave these options off, so what can I do to still include a module only if a certain configuration is active?

2 Answers 2

1

It said:

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

I think you maybe using the router-outlet in your customer modules. You need to make sure that you import router module in your modules.

Sign up to request clarification or add additional context in comments.

1 Comment

No, I am not using router-outlet in customer modules. Nevertheless I assure you that I extensively tested adding imports, before I eventually realized that I am on the wrong track...
1

While the concat call is not possible anymore it works fine when using the spread-operator ... which is also supported by TypeScript since version 2.1:

@NgModule({
    imports: [
        /* .. */
        ...environment.extraModules
    ]
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.