Error: No NgModule metadata found for ‘function(){}’.

It turned out for me it was because in my main.ts i had:
const platform = platformBrowserDynamic(); platform.bootstrapModule(AppModule);

Changing this to:
platformBrowserDynamic().bootstrapModule(AppModule);