I had a similar issue in one of my projects.
The issue for me was that I was bootstrapping my app in a different file (we had requirements on when the user could be logged in or not, we didn't want to load the app if they couldn't).
It worked with Angular 4, and when we upgraded to Angular 5 we got the error.
We had something along the lines of this:
const hack = false;
if (hack) {
platformBrowserDynamic().bootstrapModule(AppModule);
}
const bootstrap = new Bootstrap(AppModule);
bootstrap.initializeBootstrap();
We passed in our module and let the bootstrap file do the rest. We did it this way as in Angular 4 there was a bug that didn't allow the bootstrap code to be in another file or a promise, see the following:
https://github.com/angular/angular-cli/issues/3540
Angular 4.0.0 could not find bootstrap code
Changing it to be promise based seemed to have solved the issue after upgrading to Angular 5.
const bootstrap = new Bootstrap();
bootstrap.initializeBootstrap().then(() => {
console.log('user is allowed to see, bootstrap the app');
platformBrowserDynamic().bootstrapModule(AppModule);
}, (error) => {
console.log('user is not allowed access do something here', error);
});
Hope this helps.